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>
#include "xylophone.h"
using namespace std;
void solve(int N) {
vector<int> pairwise(N);
vector<int> triplet(N-1);
for (int i = 0; i < N-1; i++) pairwise[i]=query(i+1,i+2);
for (int i = 0; i < N-2; i++) triplet[i]=query(i+1,i+3);
vector<int> ans(N, 0);
ans[1] = pairwise[0];
for (int i = 2; i < N; i++) {
if (triplet[i-2] == pairwise[i-2] + pairwise[i-1]) {
if (ans[i-2] < ans[i-1]) {
ans[i] = ans[i-1] + pairwise[i-1];
} else {
ans[i] = ans[i-1] - pairwise[i-1];
}
} else {
if (ans[i-2] < ans[i-1]) {
ans[i] = ans[i-1] - pairwise[i-1];
} else {
ans[i] = ans[i-1] + pairwise[i-1];
}
}
}
int mn=10000, mx=-10000;
int mnpos=-1, mxpos=-1;
for (int i = 0; i < N; i++) {
if (mn>ans[i]) {mnpos=i; mn = ans[i];}
if (mx<ans[i]) {mxpos=i; mx = ans[i];}
}
for (int i = 0; i < N; i++) ans[i] -= (mn-1);
if (mnpos > mxpos) {
for (int i = 0; i < N; i++) {
ans[i] = N+1 - ans[i];
}
}
for (int i = 0; i < N; i++) answer(i+1, ans[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |