//Sylwia Sapkowska
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
const int oo = 1e18, K = 30;
void solve(){
int n; cin >> n;
vector<vector<int>>g(n+1, vector<int>(n+1));
for (int i = 2; i<=n; i++){
for (int j = 1; j<i; j++){
char c; cin >> c;
if (c == 'R'){
g[i][j] = g[j][i] = 1;
}
}
}
auto what = [&](int s){
vector<int>A, B;
for (int v = 1; v<=n; v++){
if (v == s) continue;
if (A.empty() || g[v][A.back()] == 1){
A.emplace_back(v);
continue;
}
if (B.empty() || g[v][B.back()] == 0){
B.emplace_back(v);
continue;
}
if (g[A.back()][B.back()] == 1){
A.emplace_back(B.back());
A.emplace_back(v);
B.pop_back();
} else {
B.emplace_back(A.back());
B.emplace_back(v);
A.pop_back();
}
}
int v = s;
if (A.empty() || g[v][A.back()] == 1){
A.emplace_back(v);
} else if (B.empty() || g[v][B.back()] == 0){
B.emplace_back(v);
} else if (g[A.back()][B.back()] == 1){
A.emplace_back(B.back());
A.emplace_back(v);
B.pop_back();
} else {
B.emplace_back(A.back());
B.emplace_back(v);
A.pop_back();
}
if (A.size() && A.back() == s) reverse(A.begin(), A.end());
if (B.size() && B.back() == s) {
reverse(B.begin(), B.end());
swap(A, B);
}
// debug(s, A, B);
cout << n << "\n";
for (auto x: A) cout << x << " ";
for (auto x: B) cout << x << " ";
cout << "\n";
};
for (int i = 1; i<=n; i++){
what(i);
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
448 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
385 ms |
51428 KB |
Output is correct |
17 |
Correct |
398 ms |
51536 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
382 ms |
51276 KB |
Output is correct |
20 |
Correct |
457 ms |
51516 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
369 ms |
51332 KB |
Output is correct |
23 |
Correct |
338 ms |
51228 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
335 ms |
51096 KB |
Output is correct |
26 |
Correct |
339 ms |
51520 KB |
Output is correct |
27 |
Correct |
18 ms |
3376 KB |
Output is correct |
28 |
Correct |
320 ms |
51556 KB |
Output is correct |
29 |
Correct |
319 ms |
51240 KB |
Output is correct |
30 |
Correct |
317 ms |
51376 KB |
Output is correct |
31 |
Correct |
322 ms |
51412 KB |
Output is correct |
32 |
Correct |
319 ms |
51232 KB |
Output is correct |
33 |
Correct |
323 ms |
51532 KB |
Output is correct |
34 |
Correct |
314 ms |
51248 KB |
Output is correct |
35 |
Correct |
336 ms |
51680 KB |
Output is correct |
36 |
Correct |
366 ms |
51524 KB |
Output is correct |
37 |
Correct |
325 ms |
51036 KB |
Output is correct |
38 |
Correct |
324 ms |
51384 KB |
Output is correct |
39 |
Correct |
342 ms |
51276 KB |
Output is correct |
40 |
Correct |
336 ms |
51392 KB |
Output is correct |
41 |
Correct |
330 ms |
51276 KB |
Output is correct |
42 |
Correct |
356 ms |
51204 KB |
Output is correct |
43 |
Correct |
326 ms |
51492 KB |
Output is correct |
44 |
Correct |
338 ms |
51148 KB |
Output is correct |
45 |
Correct |
373 ms |
51368 KB |
Output is correct |
46 |
Correct |
322 ms |
51196 KB |
Output is correct |
47 |
Correct |
326 ms |
51560 KB |
Output is correct |
48 |
Correct |
332 ms |
51252 KB |
Output is correct |
49 |
Correct |
350 ms |
51612 KB |
Output is correct |
50 |
Correct |
318 ms |
51388 KB |
Output is correct |
51 |
Correct |
328 ms |
51160 KB |
Output is correct |
52 |
Correct |
375 ms |
51496 KB |
Output is correct |
53 |
Correct |
322 ms |
51412 KB |
Output is correct |
54 |
Correct |
368 ms |
51584 KB |
Output is correct |
55 |
Correct |
353 ms |
51532 KB |
Output is correct |
56 |
Correct |
387 ms |
51540 KB |
Output is correct |
57 |
Correct |
337 ms |
51620 KB |
Output is correct |
58 |
Correct |
340 ms |
51548 KB |
Output is correct |
59 |
Correct |
337 ms |
51684 KB |
Output is correct |
60 |
Correct |
352 ms |
51532 KB |
Output is correct |
61 |
Correct |
350 ms |
51548 KB |
Output is correct |
62 |
Correct |
331 ms |
51568 KB |
Output is correct |
63 |
Correct |
335 ms |
51492 KB |
Output is correct |
64 |
Correct |
329 ms |
51548 KB |
Output is correct |
65 |
Correct |
327 ms |
51552 KB |
Output is correct |
66 |
Correct |
343 ms |
51564 KB |
Output is correct |
67 |
Correct |
335 ms |
51576 KB |
Output is correct |
68 |
Correct |
334 ms |
51548 KB |
Output is correct |
69 |
Correct |
326 ms |
51532 KB |
Output is correct |
70 |
Correct |
352 ms |
51584 KB |
Output is correct |
71 |
Correct |
350 ms |
51524 KB |
Output is correct |
72 |
Correct |
340 ms |
51480 KB |
Output is correct |
73 |
Correct |
332 ms |
51612 KB |
Output is correct |
74 |
Correct |
335 ms |
51584 KB |
Output is correct |
75 |
Correct |
336 ms |
51684 KB |
Output is correct |
76 |
Correct |
340 ms |
51532 KB |
Output is correct |
77 |
Correct |
349 ms |
51604 KB |
Output is correct |
78 |
Correct |
336 ms |
51524 KB |
Output is correct |
79 |
Correct |
387 ms |
51536 KB |
Output is correct |
80 |
Correct |
331 ms |
51512 KB |
Output is correct |
81 |
Correct |
346 ms |
51556 KB |
Output is correct |
82 |
Correct |
321 ms |
51556 KB |
Output is correct |
83 |
Correct |
330 ms |
51580 KB |
Output is correct |
84 |
Correct |
336 ms |
51480 KB |
Output is correct |
85 |
Correct |
353 ms |
51832 KB |
Output is correct |
86 |
Correct |
346 ms |
51540 KB |
Output is correct |
87 |
Correct |
19 ms |
3284 KB |
Output is correct |
88 |
Correct |
20 ms |
3268 KB |
Output is correct |
89 |
Correct |
351 ms |
51556 KB |
Output is correct |
90 |
Correct |
349 ms |
51596 KB |
Output is correct |
91 |
Correct |
21 ms |
3312 KB |
Output is correct |
92 |
Correct |
19 ms |
3316 KB |
Output is correct |
93 |
Correct |
319 ms |
51648 KB |
Output is correct |
94 |
Correct |
332 ms |
51524 KB |
Output is correct |
95 |
Correct |
19 ms |
3284 KB |
Output is correct |
96 |
Correct |
20 ms |
3316 KB |
Output is correct |
97 |
Correct |
344 ms |
51636 KB |
Output is correct |
98 |
Correct |
367 ms |
51480 KB |
Output is correct |