Submission #307234

#TimeUsernameProblemLanguageResultExecution timeMemory
307234RainbowbunnyBitwise (BOI06_bitwise)C++17
100 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define mp make_pair #define eb emplace_back #define fi first #define se second using namespace std; using cd = complex <double>; const long long INF = 1e15; const int N = 3e5 + 2; //const int mod = 1e9 + 7;//998244353;//1e9 + 7;//786433; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, p; int res = 0; bool ok[105]; vector <pair <int, int> > A[105]; signed main() { cin >> n >> p; for(int i = 1; i <= p; i++) { int sz; cin >> sz; A[i].resize(sz); } for(int i = 1; i <= p; i++) { for(auto &x : A[i]) { cin >> x.fi >> x.se; } } for(int i = 30; i >= 0; i--) { int temp = 1 << i; bool can = true; for(int j = 1; j <= p; j++) { if(ok[j]) { continue; } int cnt[4]; cnt[0] = 0; cnt[1] = 0; cnt[2] = 0; for(auto x : A[j]) { if(temp > x.se) { ++cnt[0]; } else if(x.fi >= temp) { ++cnt[2]; } else { ++cnt[1]; } } if(cnt[1] + cnt[2] == 0) { can = false; } } if(can == false) { for(int j = 1; j <= p; j++) { for(auto &x : A[j]) { if(x.fi >= temp) { x.fi -= temp; x.se -= temp; } else if(x.se >= temp) { x.se = temp - 1; } } } } else { res |= (1 << i); for(int j = 1; j <= p; j++) { if(ok[j]) { continue; } int cnt[4]; cnt[0] = 0; cnt[1] = 0; cnt[2] = 0; for(auto x : A[j]) { if(temp > x.se) { ++cnt[0]; } else if(x.fi >= temp) { ++cnt[2]; } else { ++cnt[1]; } } if(cnt[1] + cnt[2] > 1 and cnt[1] > 0) { ok[j] = true; } else if(cnt[1] == 1) { for(auto &x : A[j]) { if(x.se >= temp) { x.fi = 0; x.se = x.se - temp; } } } else if(cnt[1] == 0) { for(auto &x : A[j]) { if(x.fi >= temp) { x.fi -= temp; x.se -= temp; } } } } } } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...