Submission #1168428

#TimeUsernameProblemLanguageResultExecution timeMemory
1168428yellowtoadCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms328 KiB
#include <iostream>
using namespace std;

long long n, x, y, xx, yy, a[100010][3], ans, c[100010], b[3];

int main() {
	cin >> n;
	for (int i = 1; i <= 2*n; i++) {
		cin >> x >> y;
		if (y <= 1) yy = 1;
		else yy = 2;
		if (x < 1) xx = 1;
		else if (x > n) xx = n;
		else xx = x;
		a[xx][yy]++;
		ans += abs(x-xx)+abs(y-yy);
	}
	for (int i = 1; i <= n; i++) {
		c[i] = a[i][1]+a[i][2];
		ans += abs(a[i][1]-a[i][2])/2;
		if (abs(a[i][1]-a[i][2])%2) {
			if (a[i][1] < a[i][2]) b[2]++;
			else b[1]++;
		}
	}
	ans += abs(b[2]-b[1])/2;
	for (int i = 1; i <= n; i++) {
		ans += abs(c[i]-2);
		c[i+1] += c[i]-2;
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...