Submission #268308

#TimeUsernameProblemLanguageResultExecution timeMemory
268308imeimi2000Travelling Salesperson (CCO20_day2problem1)C++17
25 / 25
590 ms24316 KiB
#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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         cin >> E[i] + 1;
      |                ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...