Submission #317510

#TimeUsernameProblemLanguageResultExecution timeMemory
317510sofapudenBitwise (BOI06_bitwise)C++14
100 / 100
1 ms384 KiB
#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;
}
	
#Verdict Execution timeMemoryGrader output
Fetching results...