답안 #846217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846217 2023-09-07T12:34:04 Z vjudge1 ČVENK (COI15_cvenk) C++17
100 / 100
92 ms 3668 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define tol(bi) (1LL<<((int)(bi)))
int32_t main(){
	int n;cin>>n;
	vector<pair<int,int>> arr(n);
	for (int i = 0; i < n; i++){
		cin>>arr[i].first>>arr[i].second;
	}
	int crr = tol(32);
	int x = 0, y = 0;
	int ans = 0;
	while (crr>1){
		int alt = 0;
		int sag = 0;
		int orta = 0;
		for (int i = 0; i < n; i++){
			if (arr[i].first>x+crr/2-1) alt++;
			else if (arr[i].second>y+crr/2-1) sag++;
			else orta++;
		}
		//cout<<crr<<" "<<orta<<" "<<alt<<" "<<sag<<endl;
		if (alt>sag+orta){
			for (int i = 0; i < n; i++){
				if (arr[i].second>y+crr/2-1){
					ans+=arr[i].first-x+arr[i].second-y;
					ans+=crr/2;
					arr[i].first=x+crr/2;
					arr[i].second=y;
				}
				else if (arr[i].first<=x+crr/2-1){
					if (arr[i].second-y>arr[i].first-x){
						ans+=arr[i].first-x+arr[i].second-y;
						ans+=crr/2;
					}
					else {
						int yuru = -1;
						for (int j = 1; j <= crr; j <<= 1){
							int mo = (arr[i].first-x)%j;
							if (j>=arr[i].second-y+mo){
								yuru=mo;
								break;
							}
						}
						assert(yuru!=-1);
						ans+=x+crr/2-arr[i].first+yuru*2;
						ans+=arr[i].second-y;
						//zurnanin zirt dedigi yer(done)
					}
					arr[i].first=x+crr/2;
					arr[i].second=y;
				}
			}
			x+=crr/2;
		}
		else if (sag>alt+orta){
			for (int i = 0; i < n; i++){
				if (arr[i].first>x+crr/2){
					ans+=arr[i].first-x+arr[i].second-y;
					ans+=crr/2;
					arr[i].first=x;
					arr[i].second=y+crr/2;
				}
				else if (arr[i].second<=y+crr/2-1){
					if (arr[i].first-x>arr[i].second-y){
						ans+=arr[i].first-x+arr[i].second-y;
						ans+=crr/2;
					}
					else {
						int yuru = -1;
						for (int j = 1; j <= crr; j <<= 1){
							int mo = (arr[i].second-y)%j;
							if (j>=arr[i].first-x+mo){
								yuru=mo;
								break;
							}
						}
						assert(yuru!=-1);
						ans+=y+crr/2-arr[i].second+yuru*2;
						ans+=arr[i].first-x;
						//zurnanin zirt dedigi yer v2.0
					}
					arr[i].first=x;
					arr[i].second=y+crr/2;
				}
			}
			y+=crr/2;
		}
		else {
			for (int i = 0; i < n; i++){
				if (arr[i].first>x+crr/2-1){
					ans+=arr[i].first-(x+crr/2-1)+arr[i].second-y;
					arr[i].first=x+crr/2-1;
					arr[i].second=y;
				}
				else if (arr[i].second>y+crr/2-1){
					ans+=arr[i].first-x+arr[i].second-(y+crr/2-1);
					arr[i].first=x;
					arr[i].second=y+crr/2-1;
				}
			}
		}
		crr/=2;
	}
	//cout<<x<<" "<<y<<endl;
	cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 496 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 2628 KB Output is correct
2 Correct 37 ms 2392 KB Output is correct
3 Correct 40 ms 2500 KB Output is correct
4 Correct 33 ms 2392 KB Output is correct
5 Correct 47 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 3664 KB Output is correct
2 Correct 92 ms 3668 KB Output is correct
3 Correct 72 ms 3152 KB Output is correct
4 Correct 51 ms 3252 KB Output is correct
5 Correct 52 ms 3152 KB Output is correct