# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367532 | 2021-02-17T15:37:58 Z | spatarel | Travelling Salesperson (CCO20_day2problem1) | C++17 | 483 ms | 24316 KB |
#include <stdio.h> #include <stack> int main() { int n; scanf("%d", &n); bool color[1 + n][1 + n]; char edges[1 + n + 1]; for (int i = 2; i <= n; i++) { scanf("%s", edges + 1); for (int j = 1; j < i; j++) { color[i][j] = color[j][i] = (edges[j] == 'R'); } } int vertices[1 + n]; for (int u = 1; u <= n; u++) { vertices[u] = u; } for (int end = 1; end <= n; end++) { std::stack<int> reds; std::stack<int> greens; std::swap(vertices[end], vertices[n]); for (int i = 1; i <= n; i++) { int u = vertices[i]; if (reds.empty() || color[reds.top()][u]) { reds.push(u); } else if (greens.empty() || !color[greens.top()][u]) { greens.push(u); } else if (color[reds.top()][greens.top()]) { reds.push(greens.top()); greens.pop(); reds.push(u); } else { greens.push(reds.top()); reds.pop(); greens.push(u); } } std::swap(vertices[end], vertices[n]); if (!greens.empty() && greens.top() == end) { std::swap(reds, greens); } printf("%d\n", n); while (!reds.empty()) { printf("%d ", reds.top()); reds.pop(); } while (!greens.empty()) { printf("%d ", greens.top()); greens.pop(); } printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 364 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 0 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 | 0 ms | 364 KB | Output is correct |
11 | Correct | 0 ms | 364 KB | Output is correct |
12 | Correct | 0 ms | 364 KB | Output is correct |
13 | Correct | 0 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 0 ms | 364 KB | Output is correct |
16 | Correct | 440 ms | 24044 KB | Output is correct |
17 | Correct | 443 ms | 24044 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 436 ms | 24028 KB | Output is correct |
20 | Correct | 463 ms | 24108 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 449 ms | 24300 KB | Output is correct |
23 | Correct | 471 ms | 24032 KB | Output is correct |
24 | Correct | 2 ms | 364 KB | Output is correct |
25 | Correct | 447 ms | 23828 KB | Output is correct |
26 | Correct | 458 ms | 24044 KB | Output is correct |
27 | Correct | 27 ms | 1644 KB | Output is correct |
28 | Correct | 439 ms | 24044 KB | Output is correct |
29 | Correct | 433 ms | 23916 KB | Output is correct |
30 | Correct | 443 ms | 24044 KB | Output is correct |
31 | Correct | 451 ms | 23916 KB | Output is correct |
32 | Correct | 425 ms | 23916 KB | Output is correct |
33 | Correct | 441 ms | 24044 KB | Output is correct |
34 | Correct | 432 ms | 23960 KB | Output is correct |
35 | Correct | 442 ms | 24044 KB | Output is correct |
36 | Correct | 444 ms | 24172 KB | Output is correct |
37 | Correct | 437 ms | 24044 KB | Output is correct |
38 | Correct | 440 ms | 24044 KB | Output is correct |
39 | Correct | 442 ms | 23916 KB | Output is correct |
40 | Correct | 426 ms | 24044 KB | Output is correct |
41 | Correct | 441 ms | 24140 KB | Output is correct |
42 | Correct | 428 ms | 23808 KB | Output is correct |
43 | Correct | 439 ms | 24044 KB | Output is correct |
44 | Correct | 451 ms | 23916 KB | Output is correct |
45 | Correct | 428 ms | 23956 KB | Output is correct |
46 | Correct | 435 ms | 23848 KB | Output is correct |
47 | Correct | 473 ms | 24044 KB | Output is correct |
48 | Correct | 429 ms | 23996 KB | Output is correct |
49 | Correct | 445 ms | 24044 KB | Output is correct |
50 | Correct | 425 ms | 23916 KB | Output is correct |
51 | Correct | 445 ms | 23788 KB | Output is correct |
52 | Correct | 446 ms | 24044 KB | Output is correct |
53 | Correct | 443 ms | 23916 KB | Output is correct |
54 | Correct | 449 ms | 24044 KB | Output is correct |
55 | Correct | 448 ms | 24044 KB | Output is correct |
56 | Correct | 445 ms | 24044 KB | Output is correct |
57 | Correct | 458 ms | 24044 KB | Output is correct |
58 | Correct | 451 ms | 24044 KB | Output is correct |
59 | Correct | 447 ms | 24044 KB | Output is correct |
60 | Correct | 458 ms | 24044 KB | Output is correct |
61 | Correct | 448 ms | 24044 KB | Output is correct |
62 | Correct | 467 ms | 24172 KB | Output is correct |
63 | Correct | 457 ms | 24044 KB | Output is correct |
64 | Correct | 464 ms | 24044 KB | Output is correct |
65 | Correct | 465 ms | 24044 KB | Output is correct |
66 | Correct | 452 ms | 24044 KB | Output is correct |
67 | Correct | 448 ms | 24172 KB | Output is correct |
68 | Correct | 455 ms | 24044 KB | Output is correct |
69 | Correct | 448 ms | 24044 KB | Output is correct |
70 | Correct | 450 ms | 24044 KB | Output is correct |
71 | Correct | 453 ms | 24172 KB | Output is correct |
72 | Correct | 465 ms | 24172 KB | Output is correct |
73 | Correct | 472 ms | 24172 KB | Output is correct |
74 | Correct | 471 ms | 24044 KB | Output is correct |
75 | Correct | 452 ms | 24076 KB | Output is correct |
76 | Correct | 457 ms | 24044 KB | Output is correct |
77 | Correct | 460 ms | 24044 KB | Output is correct |
78 | Correct | 449 ms | 24044 KB | Output is correct |
79 | Correct | 452 ms | 24044 KB | Output is correct |
80 | Correct | 468 ms | 24172 KB | Output is correct |
81 | Correct | 466 ms | 24300 KB | Output is correct |
82 | Correct | 461 ms | 24172 KB | Output is correct |
83 | Correct | 447 ms | 24044 KB | Output is correct |
84 | Correct | 451 ms | 24316 KB | Output is correct |
85 | Correct | 454 ms | 24300 KB | Output is correct |
86 | Correct | 457 ms | 24136 KB | Output is correct |
87 | Correct | 28 ms | 1772 KB | Output is correct |
88 | Correct | 28 ms | 1644 KB | Output is correct |
89 | Correct | 462 ms | 24172 KB | Output is correct |
90 | Correct | 455 ms | 23660 KB | Output is correct |
91 | Correct | 28 ms | 1644 KB | Output is correct |
92 | Correct | 28 ms | 1644 KB | Output is correct |
93 | Correct | 483 ms | 23276 KB | Output is correct |
94 | Correct | 461 ms | 23020 KB | Output is correct |
95 | Correct | 28 ms | 1644 KB | Output is correct |
96 | Correct | 28 ms | 1644 KB | Output is correct |
97 | Correct | 465 ms | 22700 KB | Output is correct |
98 | Correct | 460 ms | 22380 KB | Output is correct |