Submission #259858

#TimeUsernameProblemLanguageResultExecution timeMemory
259858Osama_AlkhodairyXoractive (IZhO19_xoractive)C++17
100 / 100
4 ms512 KiB
#include <bits/stdc++.h> #include "interactive.h" //~ #include "grader.cpp" using namespace std; vector <int> get(vector <int> &c){ if(c.size() == 0) return {}; auto d = get_pairwise_xor(c); reverse(d.begin(), d.end()); while(d.size() && d.back() == 0){ d.pop_back(); } vector <int> ret; for(int i = 1 ; i < (int)d.size() ; i += 2){ ret.push_back(d[i]); } reverse(ret.begin(), ret.end()); return ret; } vector <int> intersect(vector <int> a, vector <int> b){ vector <int> ret; while(a.size() && b.size()){ if(a.back() == b.back()){ ret.push_back(a.back()); a.pop_back(); b.pop_back(); } else if(a.back() > b.back()){ a.pop_back(); } else{ b.pop_back(); } } reverse(ret.begin(), ret.end()); return ret; } vector <int> del(vector <int> a, vector <int> b){ vector <int> ret; while(a.size()){ if(b.size()){ if(b.back() > a.back()){ b.pop_back(); continue; } else if(b.back() == a.back()){ a.pop_back(); b.pop_back(); continue; } } ret.push_back(a.back()); a.pop_back(); } reverse(ret.begin(), ret.end()); return ret; } vector <int> guess(int n){ vector <int> ids; ids.push_back(0); for(int i = 1 ; i <= n ; i++){ ids.push_back(i); } ids.back() = (1 << 7) - 1; vector <int> ans(n + 1); ans[n] = ask(n); vector <vector <int> > f(7); for(int i = 0 ; i < 7 ; i++){ vector <int> all; for(int j = 1 ; j <= n ; j++){ if((ids[j] >> i) & 1) all.push_back(j); } auto g = get(all); all.erase(find(all.begin(), all.end(), n)); auto h = get(all); f[i] = del(g, h); f[i].push_back(0); for(auto &j : f[i]) j ^= ans[n]; } vector <int> all; for(int i = 0 ; i < 7 ; i++){ sort(f[i].begin(), f[i].end()); for(auto &j : f[i]){ all.push_back(j); } } sort(all.begin(), all.end()); all.erase(unique(all.begin(), all.end()), all.end()); for(int i = 1 ; i <= n ; i++){ vector <int> cands = all; for(int j = 0 ; j < 7 ; j++){ if((ids[i] >> j) & 1){ cands = intersect(cands, f[j]); } else{ cands = del(cands, f[j]); } } ans[i] = cands[0]; } ans.erase(ans.begin()); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...