| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 97387 | Bruteforceman | Coin Collecting (JOI19_ho_t4) | C++11 | 118 ms | 4068 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
int x[200010], y[200010];
int cnt[3][100010];
vector <int> ball[3], cell[3];
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	long long ans = 0;
	for(int i = 1; i <= n+n; i++) {
		scanf("%d %d", &x[i], &y[i]);
		if(y[i] <= 1) {
			ans += abs(y[i] - 1);
			y[i] = 1;
		} else {
			ans += abs(y[i] - 2);
			y[i] = 2;
		}
		if(x[i] <= 1) {
			ans += abs(x[i] - 1);
			x[i] = 1;
		} else if (x[i] > n) {
			ans += abs(x[i] - n);
			x[i] = n;
		}
		cnt[y[i]][x[i]] += 1;
	}
	for(int i = 1; i <= n; i++) {
		cell[1].push_back(i);
		cell[2].push_back(i);
		for(int j = 1; j <= 2; j++) {
			int p = cnt[j][i];
			while(p--) {
				ball[j].push_back(i);
			}
		}
		for(int j = 1; j <= 2; j++) {
			while(!cell[j].empty() && !ball[j].empty()) {
				int p = cell[j].back();
				int q = ball[j].back();
				ans += abs(p - q);
				cell[j].pop_back();
				ball[j].pop_back();
			}
		}
		for(int j = 1; j <= 2; j++) {
			while(!cell[3 - j].empty() && !ball[j].empty()) {
				int p = cell[3 - j].back();
				int q = ball[j].back();
				ans += abs(p - q) + 1;
				cell[3 - j].pop_back();
				ball[j].pop_back();
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
