| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 99715 | cki86201 | Coin Collecting (JOI19_ho_t4) | C++11 | 118 ms | 6460 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;
int N;
pii p[200010];
ll ans;
int X[100010][2];
ll update(int Q[2], int R[2]) {
	ll res = abs(Q[0]) + abs(Q[1]);
	Q[0] += R[0] - 1;
	Q[1] += R[1] - 1;
	if(Q[0] < 0 && Q[1] > 0) {
		int t = min(-Q[0], Q[1]);
		Q[0] += t; Q[1] -= t;
		res += t;
	}
	else if(Q[0] > 0 && Q[1] < 0) {
		int t = min(-Q[1], Q[0]);
		Q[0] -= t; Q[1] += t;
		res += t;
	}
	return res;
}
int main() {
	scanf("%d", &N);
	for(int i=1;i<=2*N;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if(x < 1) ans += 1 - x, x = 1;
		if(x > N) ans += x - N, x = N;
		if(y < 1) ans += 1 - y, y = 1;
		if(y > 2) ans += y - 2, y = 2;
		p[i] = pii(x, y);
		X[x][y-1]++;
	}
	int Q[2] = {};
	for(int i=1;i<=N;i++) {
		ans += update(Q, X[i]);
	}
	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... | ||||
