답안 #137724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137724 2019-07-28T09:09:39 Z 임유진(#3281) Bitwise (BOI06_bitwise) C++14
50 / 100
3 ms 380 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 105;


int main() {
	ios::sync_with_stdio(0);
	int N, P;
	int K[MAXN], A[MAXN], B[MAXN];
	int sum[MAXN];
	bool all[MAXN];

	cin >> N >> P;
	for(int i = 0; i < P; i++) cin >> K[i];
	for(int i = 0; i < N; i++) cin >> A[i] >> B[i];

	sum[0] = 0;
	for(int i = 1; i <= P; i++) sum[i] = sum[i - 1] + K[i - 1];
	for(int i = 0; i < P; i++) all[i] = false;

	int ans = 0;
	for(int i = 30; i >= 0; i--) {
		bool b = true;
		for(int j = 0; j < P; j++) if(!all[j]) {
			int mx = -1;
			for(int k = sum[j]; k < sum[j + 1]; k++) if(B[k] >= (1 << i))
				if(mx == -1 || A[k] >= (1 << i)) mx = k;
			if(mx == -1) {
				b = false;
				break;
			}
			else A[mx] = max(A[mx], (1 << i));
		}
		if(b) ans += (1 << i);
		for(int j = 0; j < P; j++) if(!all[j]) for(int k = sum[j]; k < sum[j + 1]; k++)
			if(A[k] < (1 << i) && (1 << i) <= B[k]) all[j] = true;
		for(int j = 0; j < P; j++) if(!all[j]) for(int k = sum[j]; k < sum[j + 1]; k++) if(A[k] >= (1 << i)) {
			A[k] -= (1 << i);
			B[k] -= (1 << i);
		}
	}

	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Correct 2 ms 380 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Correct 2 ms 256 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Correct 2 ms 376 KB Output is correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Incorrect 3 ms 380 KB Output isn't correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Incorrect 2 ms 376 KB Output isn't correct