Submission #1005234

# Submission time Handle Problem Language Result Execution time Memory
1005234 2024-06-22T09:12:21 Z emptypringlescan Tiles (BOI24_tiles) C++17
40 / 100
74 ms 14816 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	pair<int,int> arr[n];
	for(int i=0; i<n; i++) cin >> arr[i].first >> arr[i].second;
	vector<pair<int,pair<int,int> > > vert;
	for(int i=0; i<n-1; i++){
		if(arr[i].first==arr[i+1].first) vert.push_back({arr[i].first,{arr[i].second,arr[i+1].second}});
	}
	if(arr[0].first==arr[n-1].first) vert.push_back({arr[0].first,{arr[0].second,arr[n-1].second}});
	set<pair<int,int> > odd,even,all;
	set<pair<int,int> >::iterator it;
	sort(vert.begin(),vert.end());
	int ans=0,bad=0;
	for(int o=0; o<(int)vert.size(); o++){
		pair<int,pair<int,int> > i=vert[o];
		pair<int,int> ln=i.second;
		if(ln.second<ln.first) swap(ln.second,ln.first);
		it=all.upper_bound({ln.first,1e9});
		if(it!=all.begin()) it--;
		if(it!=all.end()&&it->first<=ln.first&&it->second>=ln.second){
			pair<int,int> tmp=*it;
			if((it->second-it->first)%2) bad--;
			all.erase(it);
			if(tmp.first<ln.first) all.insert({tmp.first,ln.first});
			if(ln.second<tmp.second) all.insert({ln.second,tmp.second});
			if((ln.first-tmp.first)%2) bad++;
			if((tmp.second-ln.second)%2) bad++;
		}
		else{
			it=all.lower_bound(ln);
			if(it!=all.end()&&it->first==ln.second){
				ln.second=it->second;
				if((it->second-it->first)%2) bad--;
				all.erase(it);
			}
			it=all.lower_bound(ln);
			if(it!=all.begin()) it--;
			if(it!=all.end()&&it->second==ln.first){
				ln.first=it->first;
				if((it->second-it->first)%2) bad--;
				all.erase(it);
			}
			all.insert(ln);
			if((ln.second-ln.first)%2) bad++;
		}
		if(o==(int)vert.size()-1||vert[o+1].first!=vert[o].first){
			if(bad>0){
				cout << ans;
				return 0;
			}
		}
		bool got=false;
		it=odd.lower_bound(ln);
		if(it!=odd.begin()) it--;
		vector<pair<int,int> > die;
		for(;it!=odd.end();it++){
			if(it->second<=ln.first) continue;
			if(it->first>=ln.second) break;
			if(i.first%2==0){
				cout << ans;
				return 0;
			}
			got=true;
			pair<int,int> tmp=*it;
			die.push_back(tmp);
			if(tmp.first<ln.first) odd.insert({tmp.first,ln.first});
			if(tmp.second>ln.second)odd.insert({ln.second,tmp.second});
		}
		for(auto j:die) odd.erase(j);
		die.clear();
		it=even.lower_bound(ln);
		if(it!=even.begin()) it--;
		for(;it!=even.end();it++){
			if(it->second<=ln.first) continue;
			if(it->first>=ln.second) break;
			if(i.first%2==1){
				cout << ans;
				return 0;
			}
			got=true;
			pair<int,int> tmp=*it;
			die.push_back(tmp);
			if(tmp.first<ln.first) even.insert({tmp.first,ln.first});
			if(tmp.second>ln.second)even.insert({ln.second,tmp.second});
		}
		for(auto j:die) even.erase(j);
		die.clear();
		if(!got){
			if(i.first%2==1) odd.insert(ln);
			else even.insert(ln);
		}
		if(i.first%2==1&&even.empty()){
			if(o==(int)vert.size()-1||vert[o+1].first!=vert[o].first) ans=i.first;
			if(o!=(int)vert.size()-1&&vert[o+1].first!=vert[o].first){
				if(vert[o+1].first%2==1) ans=vert[o+1].first;
				else ans=vert[o+1].first-1;
			}
		}
		else if(i.first%2==0&&odd.empty()){
			if(o==(int)vert.size()-1||vert[o+1].first!=vert[o].first) ans=i.first;
			if(o!=(int)vert.size()-1&&vert[o+1].first!=vert[o].first){
				if(vert[o+1].first%2==0) ans=vert[o+1].first;
				else ans=vert[o+1].first-1;
			}
		}
	}
	cout << ans;
	
}
/*18 9
0 2
2 2
2 1
4 1
4 0
9 0
9 2
4 2
4 4
7 4
7 3
9 3
9 6
4 6
4 5
2 5
2 4
0 4
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 344 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 6 ms 1908 KB Output is correct
3 Correct 43 ms 6672 KB Output is correct
4 Correct 22 ms 3540 KB Output is correct
5 Correct 21 ms 3540 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 41 ms 6764 KB Output is correct
9 Correct 25 ms 3792 KB Output is correct
10 Correct 36 ms 7620 KB Output is correct
11 Correct 20 ms 3540 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 48 ms 7788 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 24 ms 7120 KB Output is correct
6 Correct 42 ms 8052 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 23 ms 4704 KB Output is correct
3 Correct 23 ms 4812 KB Output is correct
4 Correct 25 ms 7880 KB Output is correct
5 Correct 43 ms 7940 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 36 ms 9416 KB Output is correct
9 Correct 36 ms 9156 KB Output is correct
10 Correct 60 ms 8644 KB Output is correct
11 Correct 61 ms 8808 KB Output is correct
12 Incorrect 30 ms 9492 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 8900 KB Output is correct
2 Correct 23 ms 4808 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 38 ms 8904 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 52 ms 9044 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 69 ms 9976 KB Output is correct
9 Correct 61 ms 9672 KB Output is correct
10 Correct 36 ms 9668 KB Output is correct
11 Correct 31 ms 9668 KB Output is correct
12 Correct 37 ms 10184 KB Output is correct
13 Correct 60 ms 8588 KB Output is correct
14 Correct 71 ms 9268 KB Output is correct
15 Correct 61 ms 9668 KB Output is correct
16 Correct 69 ms 14816 KB Output is correct
17 Correct 71 ms 14012 KB Output is correct
18 Correct 74 ms 14524 KB Output is correct
19 Correct 24 ms 4816 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 41 ms 9588 KB Output is correct
22 Correct 24 ms 5076 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 456 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 24 ms 4956 KB Output is correct
37 Correct 39 ms 7568 KB Output is correct
38 Correct 39 ms 8900 KB Output is correct
39 Correct 44 ms 7632 KB Output is correct
40 Correct 43 ms 7628 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 344 KB Output isn't correct
14 Halted 0 ms 0 KB -