Submission #622668

#TimeUsernameProblemLanguageResultExecution timeMemory
622668gromperenTravelling Salesperson (CCO20_day2problem1)C++14
25 / 25
439 ms24144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int MAXN =2e3+5; char a[MAXN][MAXN]; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i =1 ; i <= n; ++i) { for (int j = 1; j < i; ++j) { cin >> a[i][j]; a[j][i] = a[i][j]; } } for (int s = 1; s <= n; s++) { vector<int> red, blue; for (int i = 1; i <= n+1; ++i) { if (i == s) continue; if (i == n+1) i = s; if (red.empty() || a[red.back()][i] == 'R') { red.push_back(i); } else if (blue.empty() || a[blue.back()][i] == 'B') { blue.push_back(i); } else if (a[red.back()][blue.back()] == 'R') { red.push_back(blue.back()); blue.pop_back(); red.push_back(i); } else { blue.push_back(red.back()); red.pop_back(); blue.push_back(i); } if (i == s) i = n+1; } if (!blue.empty() && blue.back() == s) swap(red,blue); cout << n << "\n"; reverse(red.begin(), red.end()); for (int i : red) cout << i << " "; for (int i : blue) cout << i << " "; cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...