- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
Latest commit
106 lines (92 loc) · 1.91 KB
/
Copy pathmain.cpp
File metadata and controls
106 lines (92 loc) · 1.91 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
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
#include<bits/stdc++.h>
typedeflonglong ll;
#defineFASTios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#definePII pair<int,int>
#definePIII pair<PII,int>
#definePLL pair<ll,ll>
#definePLLL pair<PLL, ll>
#defineFOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#defineFORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#defineFORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#defineFORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#defineFORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#defineFOREACH(a, b) for (auto&(a) : (b))
#defineREP(i, n) FOR(i, 0, n)
#defineREPN(i, n) FORN(i, 1, n)
#defineSQR(x) ((ll)(x) * (x))
#defineRESET(a, b) memset(a, b, sizeof(a))
#definefi first
#definese second
#definemp make_pair
#definepb push_back
#defineALL(v) v.begin(), v.end()
#defineALLA(arr, sz) arr, arr + sz
#defineSIZE(v) (int)v.size()
#defineSORT(v) sort(ALL(v))
#defineREVERSE(v) reverse(ALL(v))
#defineSORTA(arr, sz) sort(ALLA(arr, sz))
#defineREVERSEA(arr, sz) reverse(ALLA(arr, sz))
#definePERMUTE next_permutation
#defineTC(t) while (t--)
#defineINF9e9
#defineMAX250000001
#defineMOD1000000007
#defineN6
#defineM101
usingnamespacestd;
int n, m;
string s[N];
bool v[21];
string tmp[N];
voidinput() {
cin>>m>>n;
for(int i=0;i<n;i++){
cin>>s[i];
}
return;
}
boolcheck() {
for(int i=0;i<m;i++){
for(int j=0;j<m;j++) {
if (tmp[i][j] != tmp[j][i]) {
returnfalse;
}
}
}
returntrue;
}
voiddfs(int c) {
if (c == N - 1) {
if (check()) {
for(int i=0;i<m;i++) {
cout<<tmp[i]<<'\n';
}
exit(0);
}
}
for(int i=0;i<n;i++) {
if(v[i]) continue;
tmp[c] = s[i];
v[i] = true;
dfs(c + 1);
v[i] = false;
}
}
intsolve() {
// sort string -> fast in dictionary order :O(nlogn)
sort(s, s+n);
dfs(0);
cout<<"NONE\n";
// _nP_5
return0;
}
intmain() {
FAST;
input();
solve();
// cin>>t;
// TC(t){
// solve();
// }
return0;
}