QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137732 | #6730. Coolbits | PetroTarnavskyi# | WA | 243ms | 4324kb | C++17 | 1.4kb | 2023-08-10 17:10:32 | 2023-08-10 17:10:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
bool check(int l, int r, int val, int lbit, int rbit){
//exist x: x in [l, r] and val <= x % (2 ^ rbit) < val + (2 ^ lbit);
int mod = 1 << rbit;
int L = max(0, (l / mod) - 1);
L *= mod;
L += val;
int R = L + (1 << lbit) - 1;
while(L <= r){
if(max(l, L) <= min(r, R))
return 1;
L += mod;
R += mod;
}
return 0;
}
void solve(){
int n;
cin >> n;
vector<PII> a(n);
FOR(i, 0, n)
cin >> a[i].F >> a[i].S;
int rbit = 30;
while(rbit > 0){
bool ok = 1;
FOR(i, 0, n){
//from l to r we have rbit
ok &= check(a[i].F, a[i].S, 1 << rbit, rbit, rbit + 1);
}
if(ok)
break;
rbit--;
}
rbit++;
int val = 0;
RFOR(bit, rbit, 0){
bool ok = 1;
FOR(i, 0, n)
ok &= check(a[i].F, a[i].S, val + (1 << bit), bit, rbit);
if(ok)
val += 1 << bit;
}
cout << val << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3456kb
input:
2 3 0 8 2 6 3 9 1 1 100
output:
6 100
result:
ok 2 number(s): "6 100"
Test #2:
score: -100
Wrong Answer
time: 243ms
memory: 4324kb
input:
1117 74 234256176 451122435 614716780 701954053 31102604 284818525 528763990 809400397 40637446 612671528 329403504 936190213 112402633 729525189 248142852 481053286 30877745 700834811 529884578 749041634 146522084 758550567 934650972 996096650 538751855 856147351 170918541 975066425 253153230 35361...
output:
29882460 8388608 605885728 67108864 22491373 11316782 16776650 67108864 16777216 41972008 134217728 33554432 33554432 33554432 33554432 32268396 173845856 21003086 13766220 134217728 33554432 4073141 67108864 67108864 268435456 33554432 43510327 67108864 37521185 67108864 33554432 100663296 60003201...
result:
wrong answer 2nd numbers differ - expected: '10439883', found: '8388608'