Submission #277496

# Submission time Handle Problem Language Result Execution time Memory
277496 2020-08-21T05:23:46 Z 문홍윤(#5120) Travelling Salesperson (CCO20_day2problem1) C++17
0 / 25
1 ms 512 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2e18;
const int inf=1e9;

char str[2010][2010];
int n;

void solve(int st){
    vector<int> r, b;
    r.eb(st); b.eb(st);
    for(int i=1; i<=n; i++){
        if(i==st)continue;
        int ch=r.back();
        if(str[ch][i]=='R'){
            b.pop_back();
            if(!b.size()){
                if(ch==st&&r[0]!=st){
                    reverse(all(r));
                    b.eb(ch);
                    i--;
                    continue;
                }
                else{
                    r.eb(i);
                    b.eb(i);
                }
            }
            else{
                if(str[i][b.back()]=='B'){
                    r.eb(i);
                    b.eb(i);
                }
                else{
                    r.eb(i);
                    r.eb(b.back());
                }
            }
        }
        else{
            r.pop_back();
            if(!r.size()){
                if(ch==st&&b[0]!=st){
                    reverse(all(b));
                    r.eb(ch);
                    i--;
                    continue;
                }
                else{
                    r.eb(i);
                    b.eb(i);
                }
            }
            else{
                if(str[i][r.back()]=='R'){
                    r.eb(i);
                    b.eb(i);
                }
                else{
                    b.eb(i);
                    b.eb(r.back());
                }
            }
        }
    }
    printf("%d\n", n);
    if(r[0]!=st&&b[0]!=st)while(1);
    if(r.size()){
        for(int i=0; i<r.size()-1; i++)assert(str[r[i]][r[i+1]]=='R');
    }
    if(b.size()){
        for(int i=0; i<b.size()-1; i++)assert(str[b[i]][b[i+1]]=='B');
    }
    if(r[0]==st){
        b.pop_back();
        reverse(all(b));
        for(auto i:r)printf("%d ", i);
        for(auto i:b)printf("%d ", i);
    }
    else{
        r.pop_back();
        reverse(all(r));
        for(auto i:b)printf("%d ", i);
        for(auto i:r)printf("%d ", i);
    }
    puts("");
}

int main(){
    scanf("%d", &n);
    for(int i=2; i<=n; i++)scanf("%s", str[i]+1);
    if(n==2)return !printf("2\n1 2\n2\n2 1");
    if(n==3)return !printf("3\n1 2 3\n3\n2 3 1\n3\n3 1 2");
    for(int i=2; i<=n; i++){
        for(int j=1; j<i; j++)str[j][i]=str[i][j];
    }
    for(int i=1; i<=n; i++)solve(i);
}

Compilation message

Main.cpp: In function 'void solve(int)':
Main.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i=0; i<r.size()-1; i++)assert(str[r[i]][r[i+1]]=='R');
      |                      ~^~~~~~~~~~~
Main.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(int i=0; i<b.size()-1; i++)assert(str[b[i]][b[i+1]]=='B');
      |                      ~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  102 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:103:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  103 |     for(int i=2; i<=n; i++)scanf("%s", str[i]+1);
      |                            ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Runtime error 1 ms 512 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -