# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
268308 | imeimi2000 | Travelling Salesperson (CCO20_day2problem1) | C++17 | 590 ms | 24316 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |