Submission #703017

#TimeUsernameProblemLanguageResultExecution timeMemory
703017beepbeepsheepXylophone (JOI18_xylophone)C++17
0 / 100
1 ms208 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; bool vis[5005]; int arr[5005]; void solve(int N) { int l=1,r=N,m; while (l!=r-1){ m=(l+r)>>1; if (query(m,N)==N-1) l=m; else r=m; } vis[1]=true; arr[l]=1; if (l==1){ arr[2]=query(l,l+1)+1; for (int i=3;i<=N;i++){ int res=query(i-1,i); if (arr[i-1]-res<1 || vis[arr[i-1]-res]){ arr[i]=res+arr[i-1]; vis[arr[i]]=true; } else if (res+arr[i-1]>N || vis[res+arr[i-1]]){ arr[i]=arr[i-1]-res; vis[arr[i]]=true; } else{ int res2=query(i-2,i); if (res2==res){ arr[i]=arr[i-1]-res; vis[arr[i]]=true; } else{ arr[i]=res+arr[i-1]; vis[arr[i]]=true; } } } } else{ arr[l+1]=query(l,l+1)+1; for (int i=l+2;i<=N;i++){ int res=query(i-1,i); if (arr[i-1]-res<1 || vis[arr[i-1]-res]){ vis[res+arr[i-1]]=true; arr[i]=res+arr[i-1]; } else if (res+arr[i-1]>N || vis[res+arr[i-1]]){ vis[arr[i-1]-res]=true; arr[i]=arr[i-1]-res; } else{ int res2=query(i-2,i); if (res2==res){ arr[i]=arr[i-1]-res; vis[arr[i]]=true; } else{ arr[i]=res+arr[i-1]; vis[arr[i]]=true; } } } arr[l-1]=query(l-1,l)+1; for (int i=l-2;i>=1;i--){ int res=query(i,i+1); if (arr[i-1]-res<1 || vis[arr[i+1]-res]){ vis[res+arr[i+1]]=true; arr[i]=res+arr[i+1]; } else if (res+arr[i+1]>N || vis[res+arr[i+1]]){ vis[arr[i+1]-res]=true; arr[i]=arr[i+1]-res; } else{ int res2=query(i,i+2); if (res2==res){ arr[i]=arr[i+1]-res; vis[arr[i+1]-res]=true; } else{ arr[i]=res+arr[i+1]; vis[res+arr[i+1]]=true; } } } } //for (int i=1;i<=N;i++) cerr<<arr[i]<<' '; for (int i=1;i<=N;i++) answer(i,arr[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...