Submission #362069

#TimeUsernameProblemLanguageResultExecution timeMemory
362069LawlietXoractive (IZhO19_xoractive)C++17
100 / 100
3 ms492 KiB
#include "interactive.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 110; int n; int firstValue; vector<int> values[MAXN]; vector<int> notValues[MAXN]; vector<int> allValues; void print(string name, vector<int> A) { cout << name << " -> "; for(int i = 0 ; i < (int)A.size() ; i++) printf("%d ",A[i]); printf("\n"); } vector<int> getDiff(vector<int> A, vector<int> B) { vector<int> ans; int pA = 0, pB = 0; while( pA < (int)A.size() && pB < (int)B.size() ) { if( A[pA] == B[pB] ) pA++, pB++; else if( A[pA] > B[pB] ) pB++; else ans.push_back( A[pA++] ); } while( pA < (int)A.size() ) ans.push_back( A[pA++] ); return ans; } vector<int> getIntersection(vector<int> A, vector<int> B) { vector<int> ans; int pA = 0, pB = 0; while( pA < (int)A.size() && pB < (int)B.size() ) { if( A[pA] < B[pB] ) pA++; else if( A[pA] > B[pB] ) pB++; else ans.push_back( A[pA] ), pA++, pB++; } return ans; } vector<int> getComplementary(vector<int> A) { return getDiff( allValues , A ); } vector<int> removeDuplicated(vector<int> A) { vector<int> ans; for(int i = 0 ; i < (int)A.size() ; i += 2) ans.push_back( A[i] ); return ans; } vector<int> findElements(vector<int> A) { vector<int> merge = A; merge.insert( merge.begin() , 1 ); vector<int> xorRight = get_pairwise_xor( A ); vector<int> xorMerge = get_pairwise_xor( merge ); vector<int> ans = getDiff( xorMerge , xorRight ); ans.erase( ans.begin() ); for(int i = 0 ; i < (int)ans.size() ; i++) ans[i] ^= firstValue; ans = removeDuplicated( ans ); sort( ans.begin() , ans.end() ); return ans; } void getAllValues() { set<int> s; for(int k = 0 ; (1 << k) < n ; k++) for(int j = 0 ; j < (int)values[k].size() ; j++) s.insert( values[k][j] ); for(auto it = s.begin() ; it != s.end() ; it++) allValues.push_back( *it ); } vector<int> guess(int N) { n = N; vector<int> ans; firstValue = ask( 1 ); for(int k = 0 ; (1 << k) < n ; k++) { vector<int> cur; for(int i = 0 ; i < n ; i++) if( i & (1 << k) ) cur.push_back( i + 1 ); values[k] = findElements( cur ); } getAllValues(); for(int k = 0 ; (1 << k) < n ; k++) notValues[k] = getComplementary( values[k] ); ans.push_back( firstValue ); for(int i = 1 ; i < n ; i++) { vector<int> t = allValues; for(int k = 0 ; (1 << k) < n ; k++) { if( i & (1 << k) ) t = getIntersection( t , values[k] ); else t = getIntersection( t , notValues[k] ); } ans.push_back( t[0] ); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...