Submission #1108812

#TimeUsernameProblemLanguageResultExecution timeMemory
1108812hgmhcCoreputer (IOI23_coreputer)C++17
100 / 100
2 ms516 KiB
#include <bits/stdc++.h> #include "coreputer.h" using namespace std; using ll = long long; ll qcnt; ll ask(ll x) { static int ready[16]{}, cache[16]{}; if (ready[x]) return cache[x]; ready[x] = true; vector<int> v; for(ll i=0; i<=x; ++i) { v.push_back(i); } ++qcnt; return cache[x] = run_diagnostic(v); } ll ASK(vector<int> v) { vector<int> r; for(ll i=0; i<16; ++i) { if (v[i]) r.push_back(i); } ++qcnt; return run_diagnostic(r); } vector<int> malfunctioning_cores(int n) { ll a=0, b=n-1, z; while (a<=b) { z=(a+b)/2; if (a==15) break; // cerr << a << ' ' << b << endl; if (ask(z)<0) { a=z+1; } else b=z-1; } if(a==15) b=14; assert(b<n-1); // cerr<<qcnt<<endl; // ask(b)<0 // ask(b+1)>=0 // ask(b+1)은 0일 수도, 1일 수도 있음 ll c = 0; if (c == b+1) c++; // cerr << b+1 << endl; vector<int> answer(n); ll fuck = b+1==15 ? 1 : ask(b+1); if (fuck == 0) { vector<int> v(16); fill(begin(v),begin(v)+b+2,1); // b+1 b+2 // [....][....] // n n answer[b+1] = 1; for(ll i=0; i<n; ++i) if (i!=b+1 && i!=c) { v[i]^=1; ll r=ASK(v); if (r==1) { if (i>b+1) answer[i]=1; else assert(0); } else if (r==-1) { if (i<=b+1) answer[i]=1; else assert(0); } else { answer[i]=0; } v[i]^=1; } if (accumulate(begin(answer),end(answer),0ll)%2 == 1) { answer[c] = 1; } } else if (fuck == 1) { answer[b+1] = 1; vector<int> v(16); fill(begin(v),begin(v)+b+2,1); // cerr << qcnt << endl; for(ll i=0; i<=b; ++i) if (i!=c) { v[i]^=1; // cerr << i << endl; ll r = ASK(v); if (r==1) answer[i]=0; else if (r==-1) answer[i]=1; else assert(0); v[i]^=1; } if (b+2<n) { // b b+1 b+2 // [....][1][....] // n n fill(begin(v),begin(v)+b+1,0); fill(begin(v)+b+1,begin(v)+n,1); for(ll i=b+2; i<n; ++i) if (i!=c) { v[i]^=1; // cerr << i << endl; ll r = ASK(v); if (r==1) answer[i]=0; else if (r==-1) answer[i]=1; else assert(0); v[i]^=1; } } if (accumulate(begin(answer),end(answer),0ll)%2 == 0) { answer[c] = 1; } } else { assert(0); } return answer; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...