-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAOJITP1_11_D.cpp
179 lines (157 loc) · 3.49 KB
/
AOJITP1_11_D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/06/24 Problem: AOJ ITP1_11_D / Link: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_D ----- */
/* ------問題------
Dice I と同様の方法で、入力された整数から n 個のサイコロをつくります。これらのサイコロが、全て異なるものかどうかを判定するプログラムを作成してください。同一かどうかの判定は Dice III の方法を用います。
-----問題ここまで----- */
/* -----解説等-----
3と一緒で判定をすれば良い。
----解説ここまで---- */
using uLL = unsigned long long;
const uLL MOD = 1e9;
//BEGIN CUT HERE
struct Dice {
int s[6];
void roll(char c) {
//the view from above
// N
//W E
// S
//va[0]:top
//va[1]:south
//va[2]:east
//va[3]:west
//va[4]:north
//va[5]:bottom
int b;
if (c == 'E') {
b = s[0];
s[0] = s[3];
s[3] = s[5];
s[5] = s[2];
s[2] = b;
}
if (c == 'W') {
b = s[0];
s[0] = s[2];
s[2] = s[5];
s[5] = s[3];
s[3] = b;
}
if (c == 'N') {
b = s[0];
s[0] = s[1];
s[1] = s[5];
s[5] = s[4];
s[4] = b;
}
if (c == 'S') {
b = s[0];
s[0] = s[4];
s[4] = s[5];
s[5] = s[1];
s[1] = b;
}
// migi neji
if (c == 'R') {
b = s[1];
s[1] = s[2];
s[2] = s[4];
s[4] = s[3];
s[3] = b;
}
if (c == 'L') {
b = s[1];
s[1] = s[3];
s[3] = s[4];
s[4] = s[2];
s[2] = b;
}
}
int top() {
return s[0];
}
int bottom() {
return s[5];
}
uLL hash() {
uLL res = 1;
for (int i = 0; i < 6; i++) res = res * (MOD)+s[i];
return res;
}
void print() {
cout << "Dice num: ";
FOR(i, 0, 6) {
cout << s[i] << " ";
}
cout << "Hash: " << this->hash() << endl;
cout << endl;
}
bool operator < (const Dice &x)const {
FOR(i, 0, 6)if (x.s[i] < s[i])return true;
return false;
}
};
vector<Dice> makeDices(Dice d) {
vector<Dice> res;
for (int i = 0; i < 6; i++) {
Dice t(d);
if (i == 1) t.roll('N');
if (i == 2) t.roll('S');
if (i == 3) t.roll('S'), t.roll('S');
if (i == 4) t.roll('L');
if (i == 5) t.roll('R');
for (int k = 0; k < 4; k++) {
res.push_back(t);
t.roll('E');
}
}
return res;
}
//END CUT HERE
void solve_AOJ_ITP1_11_D() {
int N; cin >> N;
vector<Dice>d(N);
FOR(k, 0, N) {
FOR(i, 0, 6) {
int val; cin >> val;
d[k].s[i] = val;
}
}
set<uLL>Se;
Se.insert(d[0].hash());
FOR(i, 1, N) {
vector<Dice>dices = makeDices(d[i]);
int flag = 0;
FOR(j, 0, SZ(dices)) {
flag |= (Se.count(dices[j].hash()));
}
if (flag) {
cout << "No" << endl;
return;
}
Se.insert(dices[i].hash());
}
cout << "Yes" << endl;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
solve_AOJ_ITP1_11_D();
return 0;
}