# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307234 | Rainbowbunny | Bitwise (BOI06_bitwise) | C++17 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |