#include <bits/stdc++.h>
using namespace std;
int n, p;
vector<int> sz;
vector<array<int,2>> hl;
bool check(int pos){
int cur = 0;
for(int i = 0; i < p; ++i){
bool good = false;
for(int j = cur; j < cur+sz[i]; ++j)if(hl[j][1]&(1<<pos))good = true;
if(!good){
for(int j = 0; j < n; ++j){
if((hl[j][1] & (1<<pos)) && !(hl[j][0] & (1<<pos))){
for(int z = 0; z < pos; ++z)hl[j][1]|=(1<<z);
}
}
return false;
}
cur+=sz[i];
}
cur = 0;
for(int i = 0; i < p; ++i){
bool good = false;
for(int j = cur; j < cur+sz[i]; ++j)if((hl[j][1] & (1<<pos)) && (hl[j][0] & (1<<pos)))good = true;
for(int j = cur; j < cur+sz[i]; ++j){
if((hl[j][1] & (1<<pos)) && !(hl[j][0] & (1<<pos))){
if(!good){
good = true;
hl[j][0] = 0;
}
else for(int z = 0; z < pos; ++z)hl[j][1]|=(1<<z);
}
}
cur+=sz[i];
}
return true;
}
int main(){
cin >> n >> p;
sz.resize(p);
hl.resize(n);
for(auto &x : sz)cin >> x;
for(auto &x : hl)cin >> x[0] >> x[1];
int ans = 0;
for(int i = 31; ~i; --i)if(check(i))ans+=(1<<i);
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |