Submission #542445

#TimeUsernameProblemLanguageResultExecution timeMemory
542445status_codingXylophone (JOI18_xylophone)C++14
0 / 100
1 ms208 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int n; int a[5005]; map<int, int> fr; int findN() { int st=2, dr=n, mij, last=-1; while(st <= dr) { mij = (st+dr)/2; //cout<<1<<' '<<mij<<'\n'; if(query(1, mij) == n-1) { last=mij; dr=mij-1; } else st=mij+1; } if(last == -1) exit(1); return last; } bool bad(int x) { if(x > n) return true; if(x <= 0) return true; if(fr[x]) return true; return false; } void solve(int N) { n=N; int p = findN(); a[p] = n; fr[n] = 1; int mini=n; for(int i=p-1;i>=1;i--) { int dif = query(i, i+1); int x1 = a[i+1] - dif; int x2 = a[i+1] + dif; if(bad(x1)) a[i]=x2; else if(bad(x2)) a[i]=x1; else { int nQ = query(i, p); if(nQ > n - mini) a[i]=n-nQ; else a[i]=x2; } mini=min(mini, a[i]); fr[ a[i] ] =1; } mini=n; for(int i=p+1;i<=n;i++) { int dif = query(i-1, i); int x1 = a[i-1] - dif; int x2 = a[i-1] + dif; if(bad(x1)) a[i]=x2; else if(bad(x2)) a[i]=x1; else { int nQ = query(p, i); if(nQ > n - mini) a[i]=n-nQ; else a[i]=x2; } mini=min(mini, a[i]); fr[ a[i] ] =1; } /* for(int i=1;i<=n;i++) cout<<a[i]<<' '; */ for(int i=1;i<=n;i++) answer(i, a[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...