Submission #631864

# Submission time Handle Problem Language Result Execution time Memory
631864 2022-08-19T03:13:03 Z jhnah917 Travelling Salesperson (CCO20_day2problem1) C++14
25 / 25
560 ms 36140 KB
#include <bits/stdc++.h>
using namespace std;

int N, A[2020][2020];

void Solve(int src){
    list<int> res;
    function<void(int)> add = [&res](int v){
        if(res.size() <= 1){ res.push_back(v); return; }
        int a = *res.begin(), b = *res.rbegin();
        if(A[v][a] == 0) res.push_front(v);
        else if(A[v][b] == 1) res.push_back(v);
        else if(A[a][b] == 0) res.pop_back(), res.push_front(b), res.push_front(v);
        else res.pop_front(), res.push_back(a), res.push_back(v);
    };

    for(int i=1; i<=N; i++) if(i != src) add(i);
    add(src);
    if(*res.begin() != src) res.reverse();

    cout << N << "\n";
    for(auto i : res) cout << i << " ";
    cout << "\n";
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    for(int i=2; i<=N; i++) for(int j=1; j<i; j++) { char c; cin >> c; A[i][j] = A[j][i] = c == 'B'; }
    for(int i=1; i<=N; i++) Solve(i);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 497 ms 35840 KB Output is correct
17 Correct 447 ms 36024 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 432 ms 35868 KB Output is correct
20 Correct 518 ms 36044 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 407 ms 35784 KB Output is correct
23 Correct 496 ms 35792 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 445 ms 35884 KB Output is correct
26 Correct 476 ms 36032 KB Output is correct
27 Correct 26 ms 4300 KB Output is correct
28 Correct 451 ms 35928 KB Output is correct
29 Correct 472 ms 35808 KB Output is correct
30 Correct 469 ms 35948 KB Output is correct
31 Correct 420 ms 35960 KB Output is correct
32 Correct 448 ms 35780 KB Output is correct
33 Correct 452 ms 35912 KB Output is correct
34 Correct 452 ms 35856 KB Output is correct
35 Correct 440 ms 36008 KB Output is correct
36 Correct 461 ms 35944 KB Output is correct
37 Correct 432 ms 35664 KB Output is correct
38 Correct 448 ms 35832 KB Output is correct
39 Correct 451 ms 35760 KB Output is correct
40 Correct 450 ms 36012 KB Output is correct
41 Correct 448 ms 35728 KB Output is correct
42 Correct 415 ms 35804 KB Output is correct
43 Correct 426 ms 36076 KB Output is correct
44 Correct 442 ms 35704 KB Output is correct
45 Correct 410 ms 35864 KB Output is correct
46 Correct 416 ms 35828 KB Output is correct
47 Correct 499 ms 36004 KB Output is correct
48 Correct 441 ms 35888 KB Output is correct
49 Correct 420 ms 36032 KB Output is correct
50 Correct 425 ms 35916 KB Output is correct
51 Correct 451 ms 35716 KB Output is correct
52 Correct 493 ms 35996 KB Output is correct
53 Correct 443 ms 35872 KB Output is correct
54 Correct 454 ms 36012 KB Output is correct
55 Correct 534 ms 36024 KB Output is correct
56 Correct 524 ms 36000 KB Output is correct
57 Correct 504 ms 35964 KB Output is correct
58 Correct 493 ms 36064 KB Output is correct
59 Correct 490 ms 36004 KB Output is correct
60 Correct 502 ms 36068 KB Output is correct
61 Correct 489 ms 35972 KB Output is correct
62 Correct 540 ms 35956 KB Output is correct
63 Correct 514 ms 36044 KB Output is correct
64 Correct 540 ms 35952 KB Output is correct
65 Correct 516 ms 36128 KB Output is correct
66 Correct 514 ms 36060 KB Output is correct
67 Correct 508 ms 35932 KB Output is correct
68 Correct 487 ms 36032 KB Output is correct
69 Correct 499 ms 35980 KB Output is correct
70 Correct 504 ms 35944 KB Output is correct
71 Correct 527 ms 36084 KB Output is correct
72 Correct 556 ms 35980 KB Output is correct
73 Correct 524 ms 35916 KB Output is correct
74 Correct 518 ms 35960 KB Output is correct
75 Correct 548 ms 35992 KB Output is correct
76 Correct 481 ms 35956 KB Output is correct
77 Correct 493 ms 35952 KB Output is correct
78 Correct 512 ms 36044 KB Output is correct
79 Correct 497 ms 35936 KB Output is correct
80 Correct 507 ms 35916 KB Output is correct
81 Correct 530 ms 36064 KB Output is correct
82 Correct 509 ms 36008 KB Output is correct
83 Correct 535 ms 35920 KB Output is correct
84 Correct 480 ms 36012 KB Output is correct
85 Correct 491 ms 36140 KB Output is correct
86 Correct 496 ms 36056 KB Output is correct
87 Correct 30 ms 4300 KB Output is correct
88 Correct 38 ms 4344 KB Output is correct
89 Correct 500 ms 35932 KB Output is correct
90 Correct 502 ms 35936 KB Output is correct
91 Correct 31 ms 4348 KB Output is correct
92 Correct 33 ms 4328 KB Output is correct
93 Correct 527 ms 35868 KB Output is correct
94 Correct 543 ms 36024 KB Output is correct
95 Correct 29 ms 4272 KB Output is correct
96 Correct 38 ms 4384 KB Output is correct
97 Correct 525 ms 35956 KB Output is correct
98 Correct 560 ms 36008 KB Output is correct