Submission #220168

#TimeUsernameProblemLanguageResultExecution timeMemory
220168anatolikCoin Collecting (JOI19_ho_t4)C++14
0 / 100
5 ms384 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	ll S = 0;
	for (int i = 0; i < 2 * n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x <= 1) {
			S += 1 - x;
			x = 1;
		}
		if (x >= n) {
			S += x - n;
			x = n;
		}
		if (y >= 2) {
			S += y - 2;
			y = 2;
		}
		if (y <= 1) {
			S += 1 - y;
			y = 1;
		}
		if (y == 1) {
			a[x - 1]++;
		}
		else
			b[x - 1]++;
	}
	ll val = 0;
	for (int i = 0; i < n; i++) {
		val += a[i];
		a[i] += b[i];
	}
	ll need = abs(val - n);
	S += need;
	ll now = 0;
	for (int i = 0; i < n; i++) {
		now += a[i];
		need = abs(2 * (i + 1) - now);
		S += need;
	}
	cout << S << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...