# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702900 | siewjh | Xylophone (JOI18_xylophone) | C++17 | 103 ms | 436 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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int A[5000];
void solve(int N) {
vector<int> a2(N), a3(N);
for (int i = 1; i <= N - 1; i++) a2[i] = query(i, i + 1);
for (int i = 1; i <= N - 2; i++) a3[i] = query(i, i + 2);
vector<int> ans(N + 1);
ans[1] = 1; ans[2] = ans[1] + a2[1];
int minv = N + 1, minind, maxv = 0, maxind;
for (int i = 3; i <= N; i++){
if (ans[i - 2] > ans[i - 1]){
if (a2[i - 2] + a2[i - 1] == a3[i - 2]) ans[i] = ans[i - 1] - a2[i - 1];
else ans[i] = ans[i - 1] + a2[i - 1];
}
else {
if (a2[i - 2] + a2[i - 1] == a3[i - 2]) ans[i] = ans[i - 1] + a2[i - 1];
else ans[i] = ans[i - 1] - a2[i - 1];
}
}
for (int i = 1; i <= N; i++) {
if (ans[i] < minv){
minv = ans[i];
minind = i;
}
if (ans[i] > maxv){
maxv = ans[i];
maxind = i;
}
}
for (int i = 1; i <= N; i++) ans[i] -= (minv - 1);
if (minind > maxind){
for (int i = 1; i <= N; i++) ans[i] = N + 1 - ans[i];
}
for (int i = 1; i <= N; i++) {
answer(i, ans[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |