Submission #1168395

#TimeUsernameProblemLanguageResultExecution timeMemory
1168395yellowtoadCoin 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], b[3], ans, c[100010];

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 j = 1; j <= 2; j++) for (int i = 1; i <= n; i++) b[j] += a[i][j];
	for (int i = 1; i <= n; i++) c[i] = a[i][1]+a[i][2];
	ans += abs(b[1]-b[2])/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...