Submission #283249

#TimeUsernameProblemLanguageResultExecution timeMemory
283249NintsiChkhaidzeXylophone (JOI18_xylophone)C++14
47 / 100
113 ms384 KiB
#include <iostream> #include <vector> #include "xylophone.h" #define pb push_back #define f first #define s second using namespace std; int ans[5005]; void solve(int N) { int l=1,r=N,v = N - 1; while (v == N - 1) v = query(l,--r); if (r + 1 <= N && ans[r + 1] == 0) ans[r + 1] = N; int indn = r + 1; if (indn - 1 > 0 && ans[indn - 1] == 0){ v = query(indn - 1,indn); ans[indn - 1] = N - v; } if (indn + 1 <= N && ans[indn + 1] == 0){ v = query(indn,indn + 1); ans[indn + 1] = N - v; } int ind = indn - 2; while (ind > 0 && ans[ind] == 0){ v = query(ind,ind + 1); int v1 = query(ind,ind + 2),val=0; if (ans[ind + 1] - v > 0) { val = ans[ind + 1] - v; int minn = min(min(val,ans[ind + 1]),ans[ind + 2]); int maxx = max(max(val,ans[ind + 1]),ans[ind + 2]); if (maxx - minn == v1) ans[ind] = val; } if (ans[ind + 1] + v <= N){ val = ans[ind + 1] + v; int minn = min(min(val,ans[ind + 1]),ans[ind + 2]); int maxx = max(max(val,ans[ind + 1]),ans[ind + 2]); if (maxx - minn == v1) ans[ind] = val; } ind--; } ind = indn + 2; while (ind <= N && ans[ind] == 0){ v = query(ind - 1,ind); int v1 = query(ind - 2,ind),val=0; if (ans[ind - 1] - v > 0) { val = ans[ind - 1] - v; int minn = min(min(val,ans[ind - 1]),ans[ind - 2]); int maxx = max(max(val,ans[ind - 1]),ans[ind - 2]); if (maxx - minn == v1) ans[ind] = val; } if (ans[ind - 1] + v <= N){ val = ans[ind - 1] + v; int minn = min(min(val,ans[ind - 1]),ans[ind - 2]); int maxx = max(max(val,ans[ind - 1]),ans[ind - 2]); if (maxx - minn == v1) ans[ind] = val; } ind++; } for (int i=1;i<=N;i++) answer(i,ans[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...