답안 #621478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
621478 2022-08-03T21:02:26 Z elkernos Travelling Salesperson (CCO20_day2problem1) C++17
25 / 25
422 ms 20856 KB
#include <bits/stdc++.h>

using namespace std;

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector col(n + 1, vector<bool>(n + 1));
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j < i; j++) {
            char c;
            cin >> c;
            col[i][j] = col[j][i] = (c == 'R');
        }
    }
    for(int s = 1; s <= n; s++) {
        vector<int> one, two;
        for(int i = 1; i <= n; i++) {
            if(i == s) {
                continue;
            }
            if(one.empty() || col[one.back()][i]) {
                one.push_back(i);
            }
            else if(two.empty() || !col[two.back()][i]) {
                two.push_back(i);
            }
            else if(col[one.back()][two.back()]) {
                one.push_back(two.back());
                two.pop_back();
                one.push_back(i);
            }
            else {
                two.push_back(one.back());
                one.pop_back();
                two.push_back(i);
            }
        }
        int i = s;
        if(one.empty() || col[one.back()][i]) {
            one.push_back(i);
        }
        else if(two.empty() || !col[two.back()][i]) {
            two.push_back(i);
        }
        else if(col[one.back()][two.back()]) {
            one.push_back(two.back());
            two.pop_back();
            one.push_back(i);
        }
        else {
            two.push_back(one.back());
            one.pop_back();
            two.push_back(i);
        }
        cout << n << '\n';
        if(!two.empty() && two.back() == s) {
            swap(one, two);
        }
        reverse(one.begin(), one.end());
        for(int i : one) {
            cout << i << " ";
        }
        for(int i : two) {
            cout << i << " ";
        }
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 344 ms 20700 KB Output is correct
17 Correct 401 ms 20716 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 385 ms 20572 KB Output is correct
20 Correct 415 ms 20700 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 350 ms 20692 KB Output is correct
23 Correct 422 ms 20488 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 334 ms 20576 KB Output is correct
26 Correct 369 ms 20724 KB Output is correct
27 Correct 28 ms 1336 KB Output is correct
28 Correct 372 ms 20744 KB Output is correct
29 Correct 341 ms 20556 KB Output is correct
30 Correct 340 ms 20724 KB Output is correct
31 Correct 351 ms 20584 KB Output is correct
32 Correct 375 ms 20568 KB Output is correct
33 Correct 362 ms 20676 KB Output is correct
34 Correct 331 ms 20616 KB Output is correct
35 Correct 366 ms 20756 KB Output is correct
36 Correct 353 ms 20780 KB Output is correct
37 Correct 399 ms 20496 KB Output is correct
38 Correct 393 ms 20668 KB Output is correct
39 Correct 366 ms 20580 KB Output is correct
40 Correct 337 ms 20736 KB Output is correct
41 Correct 342 ms 20624 KB Output is correct
42 Correct 353 ms 20632 KB Output is correct
43 Correct 365 ms 20720 KB Output is correct
44 Correct 338 ms 20504 KB Output is correct
45 Correct 355 ms 20752 KB Output is correct
46 Correct 335 ms 20564 KB Output is correct
47 Correct 358 ms 20644 KB Output is correct
48 Correct 358 ms 20588 KB Output is correct
49 Correct 350 ms 20752 KB Output is correct
50 Correct 331 ms 20660 KB Output is correct
51 Correct 328 ms 20576 KB Output is correct
52 Correct 403 ms 20856 KB Output is correct
53 Correct 337 ms 20648 KB Output is correct
54 Correct 422 ms 20680 KB Output is correct
55 Correct 339 ms 20752 KB Output is correct
56 Correct 376 ms 20728 KB Output is correct
57 Correct 393 ms 20704 KB Output is correct
58 Correct 355 ms 20780 KB Output is correct
59 Correct 341 ms 20788 KB Output is correct
60 Correct 397 ms 20776 KB Output is correct
61 Correct 337 ms 20692 KB Output is correct
62 Correct 370 ms 20744 KB Output is correct
63 Correct 353 ms 20740 KB Output is correct
64 Correct 383 ms 20748 KB Output is correct
65 Correct 367 ms 20764 KB Output is correct
66 Correct 363 ms 20848 KB Output is correct
67 Correct 372 ms 20840 KB Output is correct
68 Correct 335 ms 20848 KB Output is correct
69 Correct 361 ms 20852 KB Output is correct
70 Correct 330 ms 20752 KB Output is correct
71 Correct 374 ms 20740 KB Output is correct
72 Correct 352 ms 20660 KB Output is correct
73 Correct 365 ms 20752 KB Output is correct
74 Correct 352 ms 20856 KB Output is correct
75 Correct 358 ms 20684 KB Output is correct
76 Correct 372 ms 20788 KB Output is correct
77 Correct 349 ms 20712 KB Output is correct
78 Correct 349 ms 20752 KB Output is correct
79 Correct 331 ms 20768 KB Output is correct
80 Correct 352 ms 20840 KB Output is correct
81 Correct 347 ms 20772 KB Output is correct
82 Correct 366 ms 20708 KB Output is correct
83 Correct 356 ms 20728 KB Output is correct
84 Correct 335 ms 20812 KB Output is correct
85 Correct 345 ms 20748 KB Output is correct
86 Correct 357 ms 20816 KB Output is correct
87 Correct 22 ms 1356 KB Output is correct
88 Correct 21 ms 1336 KB Output is correct
89 Correct 350 ms 20756 KB Output is correct
90 Correct 380 ms 20776 KB Output is correct
91 Correct 24 ms 1420 KB Output is correct
92 Correct 22 ms 1352 KB Output is correct
93 Correct 362 ms 20724 KB Output is correct
94 Correct 368 ms 20704 KB Output is correct
95 Correct 24 ms 1356 KB Output is correct
96 Correct 23 ms 1436 KB Output is correct
97 Correct 360 ms 20696 KB Output is correct
98 Correct 339 ms 20748 KB Output is correct