forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG.cpp
More file actions
76 lines (62 loc) · 1.83 KB
/
G.cpp
File metadata and controls
76 lines (62 loc) · 1.83 KB
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
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
string a[22];
int n;
char board[2][11][11];
bool used[22];
void attempt(int boardid, int i) {
if (boardid == 2) {
REP(t,2) {
REP(i,n) {
REP(j,n) putchar(board[t][i][j]);
puts("");
}
puts("");
}
throw 1;
}
int boardid2 = boardid;
int i2 = i + 1;
if (i2 == n) {
++boardid2;
i2 = 0;
}
FOR(cur,1,n+n) if (!used[cur]) {
bool ok = true;
REP(j,i)
if (board[boardid][j][i] != a[cur][j]
|| board[boardid][i][j] != a[cur][j]) {
ok = false;
break;
}
if (!ok) continue;
used[cur] = true;
FOR(j,i,n-1) board[boardid][i][j] = board[boardid][j][i] = a[cur][j];
attempt(boardid2, i2);
used[cur] = false;
FOR(j,i,n-1) board[boardid][i][j] = board[boardid][j][i] = ' ';
}
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
freopen("square.in", "r", stdin);
freopen("square.out", "w", stdout);
while (cin >> n) {
FOR(i,1,n+n) cin >> a[i];
memset(used, 0, sizeof used);
memset(board, ' ', sizeof board);
try {
attempt(0, 0);
} catch (int e) {
}
}
}