# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676501 | yellowtoad | Xylophone (JOI18_xylophone) | C++17 | 0 ms | 0 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 <iostream>
using namespace std;
int main() {
int n, ans[10010], a[5010], b[5010], ax, ay, bx, by;
bool add;
cin >> n;
for (int i = 1; i < n; i++) {
cout << "Q " << i << " " << i+1 << endl;
cin >> ans[i];
if (i != n-1) {
cout << "Q " << i << " " << i+2 << endl;
cin >> ans[n+i];
}
}
a[1] = b[1] = 0;
add = 1;
a[2] = a[1]+ans[1];
b[2] = b[1]-ans[1];
for (int i = 3; i <= n; i++) {
if ((ans[i-2] == ans[i-2+n]) || (ans[i-1] == ans[i-2+n])) {
if (add) {
a[i] = a[i-1]-ans[i-1];
b[i] = b[i-1]+ans[i-1];
add = 0;
} else {
a[i] = a[i-1]+ans[i-1];
b[i] = b[i-1]-ans[i-1];
add = 1;
}
} else {
if (add) {
a[i] = a[i-1]+ans[i-1];
b[i] = b[i-1]-ans[i-1];
} else {
a[i] = a[i-1]-ans[i-1];
b[i] = b[i-1]+ans[i-1];
}
}
}
ax = ay = bx = by = 1;
for (int i = 2; i <= n; i++) {
if (a[ax] > a[i]) ax = i;
if (a[ay] < a[i]) ay = i;
if (b[bx] > b[i]) bx = i;
if (b[by] < b[i]) by = i;
}
if (ax < ay) {
cout << "A";
for (int i = 1; i <= n; i++) cout << " " << a[i]+(1-a[ax]);
cout << endl;
} else {
cout << "A";
for (int i = 1; i <= n; i++) cout << " " << b[i]+(1-b[bx]);
cout << endl;
}
}