Submission #268308

# Submission time Handle Problem Language Result Execution time Memory
268308 2020-08-16T11:06:16 Z imeimi2000 Travelling Salesperson (CCO20_day2problem1) C++17
25 / 25
590 ms 24316 KB
#include <bits/stdc++.h>

using namespace std;

int n;
char E[2001][2001];

void solve(int x) {
    vector<int> R(1, x), B(1, x);
    for (int i = 1; i <= n; ++i) {
        if (i == x) continue;
        if (E[R.back()][i] == 'R') {
            B.pop_back();
            if (B.empty() || E[B.back()][i] == 'B') {
                if (B.empty() && R[0] != x && R.back() == x) {
                    reverse(R.begin(), R.end());
                    B.push_back(R.back());
                    --i;
                    continue;
                }
                R.push_back(i);
                B.push_back(i);
            }
            else {
                R.push_back(i);
                R.push_back(B.back());
            }
        }
        else {
            R.pop_back();
            if (R.empty() || E[R.back()][i] == 'R') {
                if (R.empty() && B[0] != x && B.back() == x) {
                    reverse(B.begin(), B.end());
                    R.push_back(B.back());
                    --i;
                    continue;
                }
                R.push_back(i);
                B.push_back(i);
            }
            else {
                B.push_back(i);
                B.push_back(R.back());
            }
        }
    }
    if (R[0] != x) swap(R, B);
    for (int i : R) printf("%d ", i);
    B.pop_back();
    reverse(B.begin(), B.end());
    for (int i : B) printf("%d ", i);
    printf("\n");
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        cin >> E[i] + 1;
        for (int j = 1; j < i; ++j) {
            E[j][i] = E[i][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d\n", n);
        solve(i);
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         cin >> E[i] + 1;
      |                ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 470 ms 24056 KB Output is correct
17 Correct 551 ms 24184 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 469 ms 23928 KB Output is correct
20 Correct 473 ms 24184 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 462 ms 24000 KB Output is correct
23 Correct 506 ms 23928 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 586 ms 23928 KB Output is correct
26 Correct 502 ms 24260 KB Output is correct
27 Correct 37 ms 2344 KB Output is correct
28 Correct 509 ms 24244 KB Output is correct
29 Correct 469 ms 23992 KB Output is correct
30 Correct 469 ms 24312 KB Output is correct
31 Correct 478 ms 24128 KB Output is correct
32 Correct 467 ms 24056 KB Output is correct
33 Correct 470 ms 24184 KB Output is correct
34 Correct 464 ms 24056 KB Output is correct
35 Correct 473 ms 24056 KB Output is correct
36 Correct 481 ms 24076 KB Output is correct
37 Correct 477 ms 23912 KB Output is correct
38 Correct 479 ms 24184 KB Output is correct
39 Correct 524 ms 23872 KB Output is correct
40 Correct 509 ms 24116 KB Output is correct
41 Correct 472 ms 23928 KB Output is correct
42 Correct 470 ms 24020 KB Output is correct
43 Correct 490 ms 24080 KB Output is correct
44 Correct 491 ms 24052 KB Output is correct
45 Correct 465 ms 24056 KB Output is correct
46 Correct 516 ms 24000 KB Output is correct
47 Correct 477 ms 24312 KB Output is correct
48 Correct 466 ms 24316 KB Output is correct
49 Correct 474 ms 24048 KB Output is correct
50 Correct 469 ms 24108 KB Output is correct
51 Correct 514 ms 24076 KB Output is correct
52 Correct 478 ms 24056 KB Output is correct
53 Correct 481 ms 24056 KB Output is correct
54 Correct 541 ms 24056 KB Output is correct
55 Correct 501 ms 24156 KB Output is correct
56 Correct 501 ms 24052 KB Output is correct
57 Correct 497 ms 24184 KB Output is correct
58 Correct 500 ms 24312 KB Output is correct
59 Correct 479 ms 24144 KB Output is correct
60 Correct 506 ms 24104 KB Output is correct
61 Correct 523 ms 24312 KB Output is correct
62 Correct 479 ms 24184 KB Output is correct
63 Correct 513 ms 24056 KB Output is correct
64 Correct 503 ms 24144 KB Output is correct
65 Correct 494 ms 24180 KB Output is correct
66 Correct 506 ms 24312 KB Output is correct
67 Correct 488 ms 24056 KB Output is correct
68 Correct 468 ms 24056 KB Output is correct
69 Correct 484 ms 24184 KB Output is correct
70 Correct 563 ms 24184 KB Output is correct
71 Correct 506 ms 24192 KB Output is correct
72 Correct 520 ms 24312 KB Output is correct
73 Correct 517 ms 24116 KB Output is correct
74 Correct 564 ms 24028 KB Output is correct
75 Correct 511 ms 24056 KB Output is correct
76 Correct 480 ms 24056 KB Output is correct
77 Correct 473 ms 24180 KB Output is correct
78 Correct 488 ms 24184 KB Output is correct
79 Correct 489 ms 24184 KB Output is correct
80 Correct 484 ms 24184 KB Output is correct
81 Correct 503 ms 24184 KB Output is correct
82 Correct 514 ms 24056 KB Output is correct
83 Correct 487 ms 24056 KB Output is correct
84 Correct 521 ms 24056 KB Output is correct
85 Correct 503 ms 24136 KB Output is correct
86 Correct 526 ms 24092 KB Output is correct
87 Correct 38 ms 2424 KB Output is correct
88 Correct 44 ms 2424 KB Output is correct
89 Correct 499 ms 24036 KB Output is correct
90 Correct 476 ms 24088 KB Output is correct
91 Correct 30 ms 2424 KB Output is correct
92 Correct 33 ms 2424 KB Output is correct
93 Correct 590 ms 24176 KB Output is correct
94 Correct 503 ms 24228 KB Output is correct
95 Correct 43 ms 2424 KB Output is correct
96 Correct 31 ms 2432 KB Output is correct
97 Correct 492 ms 24052 KB Output is correct
98 Correct 500 ms 24108 KB Output is correct