Submission #951230

# Submission time Handle Problem Language Result Execution time Memory
951230 2024-03-21T12:41:00 Z PM1 Bitwise (BOI06_bitwise) C++17
100 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define ll long long int
const ll mxn=105;
ll n,p,cnt[mxn],ans=0,z=1;
vector<pair<ll,ll>>v[mxn];
int main(){
	cin>>n>>p;
	for(ll i=1;i<=p;i++)
		cin>>cnt[i];
	for(ll i=1;i<=p;i++){
		while(cnt[i]--){
			ll a,b;
			cin>>a>>b;
			v[i].push_back({a,b});
		}
	}
	for(ll k=31;k>=0;k--){
		bool t=1;
		for(ll i=1;i<=p;i++){
			ll g=0,gg=0;
			for(auto j:v[i]){
				if(j.fr>=(z<<k) && j.sc>=(z<<k))g++;
				else if(j.sc>=(z<<k))gg++;
			}
			if(g+gg==0){
				t=0;
				break;
			}
		}
		if(!t){
			for(ll i=1;i<=p;i++){
				for(ll j=0;j<v[i].size();j++){
					auto y=v[i][j];
					if(y.fr>=(z<<k) && y.sc>=(z<<k)){
						v[i][j].fr-=(z<<k);
						v[i][j].sc-=(z<<k);
					}
				}
			}	
		}
		else{
			ans+=(z<<k);
			for(ll i=1;i<=p;i++){
				ll g=0,gg=0;
				for(auto j:v[i]){
					if(j.fr>=(z<<k) && j.sc>=(z<<k))g++;
					else if(j.sc>=(z<<k))gg++;
				}
				if(g){
					for(ll j=0;j<v[i].size();j++){
						auto y=v[i][j];
						if(y.fr>=(z<<k) && y.sc>=(z<<k)){
							v[i][j].fr-=(z<<k);
							v[i][j].sc-=(z<<k);
						}
					}
				}
				else{
					for(ll j=0;j<v[i].size();j++){
						auto y=v[i][j];
						if(y.fr<(z<<k) && y.sc>=(z<<k)){
							v[i][j].fr-=(z<<k);
							v[i][j].sc-=(z<<k);
							break;
						}
					}
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

Compilation message

bitwise.cpp: In function 'int main()':
bitwise.cpp:35:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(ll j=0;j<v[i].size();j++){
      |                ~^~~~~~~~~~~~
bitwise.cpp:53:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |      for(ll j=0;j<v[i].size();j++){
      |                 ~^~~~~~~~~~~~
bitwise.cpp:62:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |      for(ll j=0;j<v[i].size();j++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct