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;
bool sign[5005];
void solve(int N) {
map<pair<int,int>,int> df;
for (int i=1;i<=N;i++) {
if (i+1<=N) {
df[{i,i+1}]=query(i,i+1);
}
if (i+2<=N) {
df[{i,i+2}]=query(i,i+2);
}
}
for (int i=1;i<=N;i++) {
if (df[{i,i+2}]==df[{i,i+1}]+df[{i+1,i+2}]) {
sign[i]=sign[i-1]; continue;
}
sign[i]=1^sign[i-1];
}
int og[N+5];
og[1]=0;
int mn=0;
for (int i=2;i<=N;i++) {
if (sign[i-1]==0) {
og[i]=og[i-1]+df[{i-1,i}];
}
else {
og[i]=og[i-1]-df[{i-1,i}];
}
mn=min(mn,og[i]);
}
mn=1-mn;
int ans[N+5];
bool f1=false,gg=false;
for (int i=1;i<=N;i++) {
ans[i]=og[i]+mn;
if (ans[i]==1) f1=true;
if (ans[i]==N && !f1) gg=true;
}
for (int i=1;i<=N;i++) {
if (gg) ans[i]=N+1-ans[i];
answer(i,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... |