#include <iostream>
#include <string>
#include <deque>
#include <algorithm>
using namespace std;
const int NMAX = 2000;
int N;
string m[NMAX + 2];
///0-> BLUE
///1-> RED
bool Edge(int x, int y) {
if(x < y) {
swap(x, y);
}
if(m[x][y] == 'B') {
return 0;
}
return 1;
}
deque <int> dq;
void Push(int vert) {
if(dq.empty()) {
dq.push_back(vert);
} else {
if(Edge(dq.back(), vert) == 1) {
dq.push_back(vert);
} else if(Edge(dq.front(), vert) == 0) {
dq.push_front(vert);
} else if(Edge(dq.front(), dq.back()) == 1) {
int frontVert = dq.front();
dq.pop_front();
dq.push_back(frontVert);
dq.push_back(vert);
} else {
int backVert = dq.back();
dq.pop_back();
dq.push_front(backVert);
dq.push_front(vert);
}
}
}
void SolveFor(int vert) {
dq.clear();
for(int i = 0; i < N; i++) {
if(i != vert) {
Push(i);
}
}
Push(vert);
if(dq.back() == vert) {
reverse(dq.begin(), dq.end());
}
cout << N << '\n';
for(int v : dq) {
cout << v + 1 << ' ';
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for(int i = 1; i < N; i++) {
cin >> m[i];
}
for(int i = 0; i < N; i++) {
SolveFor(i);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
441 ms |
22412 KB |
Output is correct |
17 |
Correct |
413 ms |
22400 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
439 ms |
22252 KB |
Output is correct |
20 |
Correct |
451 ms |
22380 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
406 ms |
22380 KB |
Output is correct |
23 |
Correct |
435 ms |
22124 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
420 ms |
22124 KB |
Output is correct |
26 |
Correct |
434 ms |
22252 KB |
Output is correct |
27 |
Correct |
25 ms |
1644 KB |
Output is correct |
28 |
Correct |
437 ms |
22352 KB |
Output is correct |
29 |
Correct |
490 ms |
22252 KB |
Output is correct |
30 |
Correct |
410 ms |
22380 KB |
Output is correct |
31 |
Correct |
418 ms |
22252 KB |
Output is correct |
32 |
Correct |
404 ms |
22288 KB |
Output is correct |
33 |
Correct |
452 ms |
22368 KB |
Output is correct |
34 |
Correct |
410 ms |
22252 KB |
Output is correct |
35 |
Correct |
448 ms |
22380 KB |
Output is correct |
36 |
Correct |
432 ms |
22380 KB |
Output is correct |
37 |
Correct |
408 ms |
22128 KB |
Output is correct |
38 |
Correct |
414 ms |
22252 KB |
Output is correct |
39 |
Correct |
414 ms |
22220 KB |
Output is correct |
40 |
Correct |
395 ms |
22380 KB |
Output is correct |
41 |
Correct |
416 ms |
22132 KB |
Output is correct |
42 |
Correct |
437 ms |
22244 KB |
Output is correct |
43 |
Correct |
399 ms |
22508 KB |
Output is correct |
44 |
Correct |
413 ms |
22252 KB |
Output is correct |
45 |
Correct |
405 ms |
22380 KB |
Output is correct |
46 |
Correct |
426 ms |
22252 KB |
Output is correct |
47 |
Correct |
443 ms |
22396 KB |
Output is correct |
48 |
Correct |
405 ms |
22364 KB |
Output is correct |
49 |
Correct |
401 ms |
22380 KB |
Output is correct |
50 |
Correct |
402 ms |
22252 KB |
Output is correct |
51 |
Correct |
413 ms |
22116 KB |
Output is correct |
52 |
Correct |
437 ms |
22312 KB |
Output is correct |
53 |
Correct |
406 ms |
22380 KB |
Output is correct |
54 |
Correct |
445 ms |
22380 KB |
Output is correct |
55 |
Correct |
442 ms |
22380 KB |
Output is correct |
56 |
Correct |
451 ms |
22460 KB |
Output is correct |
57 |
Correct |
437 ms |
22508 KB |
Output is correct |
58 |
Correct |
422 ms |
22296 KB |
Output is correct |
59 |
Correct |
441 ms |
22608 KB |
Output is correct |
60 |
Correct |
429 ms |
22356 KB |
Output is correct |
61 |
Correct |
426 ms |
22380 KB |
Output is correct |
62 |
Correct |
452 ms |
22412 KB |
Output is correct |
63 |
Correct |
436 ms |
22380 KB |
Output is correct |
64 |
Correct |
483 ms |
22528 KB |
Output is correct |
65 |
Correct |
437 ms |
22508 KB |
Output is correct |
66 |
Correct |
433 ms |
22636 KB |
Output is correct |
67 |
Correct |
426 ms |
22388 KB |
Output is correct |
68 |
Correct |
431 ms |
22508 KB |
Output is correct |
69 |
Correct |
442 ms |
22380 KB |
Output is correct |
70 |
Correct |
428 ms |
22512 KB |
Output is correct |
71 |
Correct |
441 ms |
22508 KB |
Output is correct |
72 |
Correct |
456 ms |
22508 KB |
Output is correct |
73 |
Correct |
442 ms |
22360 KB |
Output is correct |
74 |
Correct |
448 ms |
22508 KB |
Output is correct |
75 |
Correct |
460 ms |
22380 KB |
Output is correct |
76 |
Correct |
440 ms |
22636 KB |
Output is correct |
77 |
Correct |
428 ms |
22380 KB |
Output is correct |
78 |
Correct |
433 ms |
22508 KB |
Output is correct |
79 |
Correct |
427 ms |
22508 KB |
Output is correct |
80 |
Correct |
445 ms |
22452 KB |
Output is correct |
81 |
Correct |
439 ms |
22380 KB |
Output is correct |
82 |
Correct |
443 ms |
22472 KB |
Output is correct |
83 |
Correct |
470 ms |
22432 KB |
Output is correct |
84 |
Correct |
426 ms |
22380 KB |
Output is correct |
85 |
Correct |
424 ms |
22380 KB |
Output is correct |
86 |
Correct |
426 ms |
22576 KB |
Output is correct |
87 |
Correct |
27 ms |
1644 KB |
Output is correct |
88 |
Correct |
27 ms |
1772 KB |
Output is correct |
89 |
Correct |
431 ms |
22508 KB |
Output is correct |
90 |
Correct |
433 ms |
22380 KB |
Output is correct |
91 |
Correct |
26 ms |
1644 KB |
Output is correct |
92 |
Correct |
26 ms |
1644 KB |
Output is correct |
93 |
Correct |
430 ms |
22508 KB |
Output is correct |
94 |
Correct |
454 ms |
22448 KB |
Output is correct |
95 |
Correct |
26 ms |
1644 KB |
Output is correct |
96 |
Correct |
28 ms |
1624 KB |
Output is correct |
97 |
Correct |
429 ms |
22436 KB |
Output is correct |
98 |
Correct |
439 ms |
22380 KB |
Output is correct |