Submission #45497

#TimeUsernameProblemLanguageResultExecution timeMemory
45497bogdan10bosLibrary (JOI18_library)C++14
19 / 100
2005 ms668 KiB
#include <bits/stdc++.h> using namespace std; //#define DEBUG #ifndef DEBUG #include "library.h" #endif // DEBUG #ifdef DEBUG int Query(const vector<int>& M); void Answer(const vector<int>& res); #endif int _N; int ask(vector<int> v) { int N = _N; vector<int> f; f.resize(N); for(int i = 1; i <= N; i++) f[i - 1] = 0; for(auto x: v) f[x - 1] = 1; return Query(f); } void Solve(int N) { if(N == 1) { vector<int> ans; ans.push_back(1); Answer(ans); return; } _N = N; vector<int> edg[1005]; for(int i = 1; i <= N; i++) edg[i].clear(); for(int i = 1; i <= N; i++) for(int j = i + 1; j <= N; j++) { vector<int> v; v.push_back(i); v.push_back(j); int ans = ask(v); if(ans == 1) { edg[i].push_back(j); edg[j].push_back(i); } } vector<int> ans; for(int i = 1; i <= N; i++) if(edg[i].size() == 1) { ans.push_back(i); ans.push_back(edg[i][0]); break; } for(int i = 3; i <= N; i++) { int x = ans[i - 2]; int y = ans[i - 3]; int nxt = y ^ edg[x][0] ^ edg[x][1]; ans.push_back(nxt); } Answer(ans); } #ifdef DEBUG namespace { struct Judge { int N; int A[1002]; int pos[1002]; bool f[1002]; int query_c; bool answered; void init() { freopen("1.in", "r", stdin); query_c=0; int ret=scanf("%d",&N); ret++; answered=false; for(int i=0;i<N;i++)ret=scanf("%d",&A[i]),pos[A[i]]=i; } int query(const vector<int>& M) { if(query_c==20000) { puts("Wrong Answer [3]"); exit(0); } if(int(M.size())!=N) { puts("Wrong Answer [1]"); exit(0); } bool all_zero=true; for(int i=0;i<N;i++) { if(M[i]!=0&&M[i]!=1) { puts("Wrong Answer [2]"); exit(0); } if(M[i]==1)all_zero=false; } if(all_zero) { puts("Wrong Answer [2]"); exit(0); } memset(f,0,sizeof(f)); for(int i=0;i<N;i++)if(M[i])f[pos[i+1]]=true; bool las=false; int r=0; for(int i=0;i<N;i++) { if(las==false&&f[i]==true)r++; las=f[i]; } query_c++; return r; } void answer(const vector<int>& res) { bool f1=true,f2=true; if(int(res.size())!=N) { puts("Wrong Answer [4]"); exit(0); } if(answered) { puts("Wrong Answer [7]"); exit(0); } answered=true; memset(f,0,sizeof(f)); for(int i=0;i<N;i++) { if(res[i]<=0||res[i]>N) { puts("Wrong Answer [5]"); exit(0); } if(f[res[i]]) { puts("Wrong Answer [6]"); exit(0); } f[res[i]]=true; } for(int i=0;i<N;i++) { f1&=A[i]==res[i]; f2&=A[i]==res[N-i-1]; } if(!f1&&!f2) { puts("Wrong Answer [8]"); exit(0); } } void end() { if(!answered)puts("Wrong Answer [7]"); else printf("Accepted : %d\n",query_c); } }judge; } int Query(const vector<int>& M) { return judge.query(M); } void Answer(const vector<int>& res) { judge.answer(res); } int main() { judge.init(); Solve(judge.N); judge.end(); } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...