Submission #566144

#TimeUsernameProblemLanguageResultExecution timeMemory
566144UzoufXylophone (JOI18_xylophone)C++14
0 / 100
1 ms208 KiB
#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]=true; sign[i+1]=true; i++; continue; } sign[i]=1^sign[i-1]; } int og[N+5]; og[1]=0; int mn=INT_MAX; 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; int ans[N+5]; bool f1=false,gg=false; for (int i=1;i<=N;i++) { ans[i]=og[i]+mn+1; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...