Submission #137988

# Submission time Handle Problem Language Result Execution time Memory
137988 2019-07-28T17:47:54 Z sebinkim Bitwise (BOI06_bitwise) C++14
100 / 100
2 ms 380 KB
#include <bits/stdc++.h>

using namespace std;

int S[111], L[111], R[111];
int n, k, s;

bool check(int t)
{
	int i, j;
	bool f, ret;
	
	ret = 1;
	
	for(i=1, j=1; i<=k; i++){
		for(f=0; j<=S[i]; j++){
			if(L[j] & R[j] & t){
				L[j] -= t; R[j] -= t;
				f = 1;
			}
		}
		
		j = S[i - 1] + 1;
		
		for(; j<=S[i]; j++){
			if(R[j] & t){
				if(f) R[j] = t - 1;
				else f = 1;
			}
		}
		
		ret &= f;
	}
	
	for(i=1; i<=n; i++){
		if(R[i] & t){
			if(ret) L[i] = 0, R[i] -= t;
			else R[i] = t - 1;
		}
	}
	
	return ret;
}

int main()
{
	int i;
	
	scanf("%d%d", &n, &k);
	
	for(i=1; i<=k; i++){
		scanf("%d", S + i);
		S[i] += S[i - 1];
	}
	
	for(i=1; i<=n; i++){
		scanf("%d%d", L + i, R + i);
	}
	
	for(i=30; i>=0; i--){
		if(check(1 << i)){
			s |= 1 << i;
		}
	}
	
	printf("%d\n", s);
	
	return 0;
}

Compilation message

bitwise.cpp: In function 'int main()':
bitwise.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
bitwise.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", S + i);
   ~~~~~^~~~~~~~~~~~~
bitwise.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", L + i, R + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct