#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int n, p, sz[101], lo[101], hi[101];
bool check(int pos) {
for (int i = 0, idx = 0; idx < p; i += sz[idx], idx++) {
bool possible = false;
FOR(j, i, i + sz[idx]) if (hi[j] & (1 << pos)) possible = true;
if (!possible) {
FOR(j, 0, n) {
if ((hi[j] & (1 << pos)) && !(lo[j] & (1 << pos))) {
FOR(k, 0, pos) hi[j] |= (1 << k);
}
}
return false;
}
}
for (int i = 0, idx = 0; idx < p; i += sz[idx], idx++) {
bool assigned = false;
FOR(j, i, i + sz[idx]) if ((hi[j] & (1 << pos)) && (lo[j] & (1 << pos))) assigned = true;
FOR(j, i, i + sz[idx]) {
if ((hi[j] & (1 << pos)) && !(lo[j] & (1 << pos))) {
if (!assigned) {
assigned = true;
lo[j] = 0;
} else FOR(k, 0, pos) hi[j] |= (1 << k);
}
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> p;
FOR(i, 0, p) cin >> sz[i];
FOR(i, 0, n) cin >> lo[i] >> hi[i];
int ans = 0;
for (int i = 31; ~i; i--) if (check(i)) ans |= 1 << i;
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
380 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
300 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
7 ms |
376 KB |
Output is correct |