Submission #373105

# Submission time Handle Problem Language Result Execution time Memory
373105 2021-03-03T11:08:10 Z Vladth11 Travelling Salesperson (CCO20_day2problem1) C++14
25 / 25
845 ms 24428 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
//#include "shoes.h"

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 2001;
const ll INF = (1LL << 31);
const ll MOD = 1000000007;
const ll BLOCK = 316;
const ll nr_of_bits = 20;
const double eps = 0.0000000001;

char mat[NMAX][NMAX];

struct muchie{
    int first, cul, second;
};

class lant{
public:
    deque <muchie> dq;
    int primul;
    void init(){
        primul = -1;
        while(dq.size())
            dq.pop_back();
    }
    void insert(int i){
        if(dq.size() == 0 && primul == -1){
            primul = i;
            return;
        }else if(dq.size() == 0){
            if(mat[i][primul] == 'R')
            dq.push_front({i, 0, primul});
            else dq.push_back({primul, 1, i});
            return;
        }
        int st = dq.front().first;
        int dr = dq.back().second;
        ///putem alipi la stanga sau dreapta
        if(mat[st][i] == 'R'){
            dq.push_front({i, 0, st});
            return;
        }else if(mat[st][i] == 'B' && (dq.front().cul == 1)){
            dq.push_front({i, 1, st});
            return;
        }else if(mat[dr][i] == 'B'){
            dq.push_back({dr, 1, i});
            return;
        }else if(mat[dr][i] == 'R' && (dq.back().cul == 0)){
            dq.push_back({dr, 0, i});
            return;
        }
        if(mat[st][dr] == 'R'){
            dq.pop_back();
            dq.push_front({dr, 0, st});
            insert(i);
            return;
        }else{
            dq.pop_front();
            dq.push_back({dr, 1, st});
            insert(i);
            return;
        }
    }
}l;

int main() {
    int n, i, j;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < i; j++){
            cin >> mat[i][j];
            mat[j][i] = mat[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        l.init();
        for(int j = 1; j <= n; j++){
            if(i == j)
                continue;
            l.insert(j);
        }
        l.insert(i);
        cout << n << "\n";
        if(l.dq.front().first == i){
            for(auto x : l.dq){
                cout << x.first << " ";
            }
            cout << l.dq.back().second << " ";
        }else{
            while(l.dq.size()){
                cout << l.dq.back().second << " ";
                if(l.dq.size() == 1){
                    cout << l.dq.back().first << " ";
                }
                l.dq.pop_back();
            }
        }
        cout << "\n";
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:78:12: warning: unused variable 'i' [-Wunused-variable]
   78 |     int n, i, j;
      |            ^
Main.cpp:78:15: warning: unused variable 'j' [-Wunused-variable]
   78 |     int n, i, j;
      |               ^
# 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 492 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 384 KB Output is correct
16 Correct 766 ms 22648 KB Output is correct
17 Correct 822 ms 22700 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 737 ms 22636 KB Output is correct
20 Correct 765 ms 22664 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 757 ms 22636 KB Output is correct
23 Correct 737 ms 22508 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 732 ms 22764 KB Output is correct
26 Correct 758 ms 22752 KB Output is correct
27 Correct 47 ms 2444 KB Output is correct
28 Correct 729 ms 22764 KB Output is correct
29 Correct 731 ms 22636 KB Output is correct
30 Correct 739 ms 22636 KB Output is correct
31 Correct 722 ms 22508 KB Output is correct
32 Correct 724 ms 22608 KB Output is correct
33 Correct 755 ms 22636 KB Output is correct
34 Correct 711 ms 22508 KB Output is correct
35 Correct 734 ms 22636 KB Output is correct
36 Correct 728 ms 22636 KB Output is correct
37 Correct 739 ms 21996 KB Output is correct
38 Correct 728 ms 22328 KB Output is correct
39 Correct 716 ms 21960 KB Output is correct
40 Correct 739 ms 22252 KB Output is correct
41 Correct 726 ms 22124 KB Output is correct
42 Correct 764 ms 21948 KB Output is correct
43 Correct 742 ms 22148 KB Output is correct
44 Correct 727 ms 22124 KB Output is correct
45 Correct 733 ms 22252 KB Output is correct
46 Correct 756 ms 22260 KB Output is correct
47 Correct 773 ms 22300 KB Output is correct
48 Correct 761 ms 22156 KB Output is correct
49 Correct 751 ms 22172 KB Output is correct
50 Correct 763 ms 22088 KB Output is correct
51 Correct 729 ms 21888 KB Output is correct
52 Correct 749 ms 22156 KB Output is correct
53 Correct 755 ms 22124 KB Output is correct
54 Correct 736 ms 22252 KB Output is correct
55 Correct 758 ms 22216 KB Output is correct
56 Correct 789 ms 22380 KB Output is correct
57 Correct 754 ms 24300 KB Output is correct
58 Correct 751 ms 24300 KB Output is correct
59 Correct 761 ms 24172 KB Output is correct
60 Correct 766 ms 24172 KB Output is correct
61 Correct 784 ms 24200 KB Output is correct
62 Correct 742 ms 24172 KB Output is correct
63 Correct 758 ms 24284 KB Output is correct
64 Correct 769 ms 24044 KB Output is correct
65 Correct 757 ms 24044 KB Output is correct
66 Correct 752 ms 24044 KB Output is correct
67 Correct 845 ms 24172 KB Output is correct
68 Correct 789 ms 24172 KB Output is correct
69 Correct 747 ms 24172 KB Output is correct
70 Correct 753 ms 24044 KB Output is correct
71 Correct 751 ms 24044 KB Output is correct
72 Correct 742 ms 24300 KB Output is correct
73 Correct 739 ms 24300 KB Output is correct
74 Correct 742 ms 24116 KB Output is correct
75 Correct 749 ms 24172 KB Output is correct
76 Correct 771 ms 24192 KB Output is correct
77 Correct 827 ms 24172 KB Output is correct
78 Correct 795 ms 24172 KB Output is correct
79 Correct 755 ms 24300 KB Output is correct
80 Correct 746 ms 24172 KB Output is correct
81 Correct 789 ms 24380 KB Output is correct
82 Correct 766 ms 24428 KB Output is correct
83 Correct 752 ms 24172 KB Output is correct
84 Correct 771 ms 24376 KB Output is correct
85 Correct 744 ms 24300 KB Output is correct
86 Correct 738 ms 24172 KB Output is correct
87 Correct 46 ms 2412 KB Output is correct
88 Correct 46 ms 2540 KB Output is correct
89 Correct 744 ms 24300 KB Output is correct
90 Correct 735 ms 24164 KB Output is correct
91 Correct 47 ms 2412 KB Output is correct
92 Correct 46 ms 2412 KB Output is correct
93 Correct 735 ms 24172 KB Output is correct
94 Correct 728 ms 24232 KB Output is correct
95 Correct 46 ms 2412 KB Output is correct
96 Correct 50 ms 2540 KB Output is correct
97 Correct 734 ms 24172 KB Output is correct
98 Correct 724 ms 24172 KB Output is correct