Submission #926140

#TimeUsernameProblemLanguageResultExecution timeMemory
926140parlimoosBitwise (BOI06_bitwise)C++14
100 / 100
1 ms600 KiB
//Be Name KHODA #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned int ui; #define pb push_back #define pp pop_back #define lb lower_bound #define ub upper_bound #define cl clear #define bg begin #define arr(x) array<int , x> #define endl '\n' int n , m; vector<int> a; vector<ui> b[100]; multiset<ui> ord[100]; ui sgs[100][2] , infs[100][2]; void init(){ for(int i = 0 ; i < n ; i++){ ui d = 0; for(int bit = 31 ; bit >= 0 ; bit--){ if(((sgs[i][1] >> bit) & 1) != ((sgs[i][0] >> bit) & 1)) break; if(((sgs[i][1] >> bit) & 1)) d += (1 << bit); } infs[i][0] = d , infs[i][1] = (sgs[i][1] ^ d); } int l = 0; for(int i = 0 ; i < m ; i++){ for(int j = l ; j < l + a[i] ; j++) b[i].pb(infs[j][0]) , ord[i].insert(infs[j][1]); l += a[i]; } } bool jg(int inx , ui x){ multiset<ui> q = ord[inx]; for(ui el : b[inx]) x &= (~el); for(int bit = 31 ; bit >= 0 ;){ int mx = *(--q.end()); // cout << bit << " " << mx << "!!\n"; if(((x >> bit) & 1) and !((mx >> bit) & 1)){ // cout << bit << " " << mx << "::\n"; return false; } if(!((x >> bit) & 1) and ((mx >> bit) & 1)) return true; if(((x >> bit) & 1) and ((mx >> bit) & 1)){ q.erase(q.find(mx)) , q.insert(mx ^ (1 << bit)); x ^= (1 << bit); } mx = *(--q.end()); if(!((mx >> bit) & 1)) bit--; } if(x > 0) return false; return true; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0 ; i < m ; i++){ int d; cin >> d; a.pb(d); } for(int i = 0 ; i < n ; i++) cin >> sgs[i][0] >> sgs[i][1]; init(); ui o = 0; // cout << jg(1 , 6) << "||\n"; for(int bit = 31 ; bit >= 0 ; bit--){ bool flg = 1; for(int i = 0 ; i < m ; i++) if(!jg(i , o ^ (1 << bit))) flg = 0; if(flg) o ^= (1 << bit); } cout << o; }
#Verdict Execution timeMemoryGrader output
Fetching results...