답안 #142784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142784 2019-08-11T02:26:39 Z DrumpfTheGodEmperor Coin Collecting (JOI19_ho_t4) C++14
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, x[N], y[N], ans = 0, compressY[3], compressX[N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n * 2) cin >> x[i] >> y[i];
	//Solve for x and y independently.
	//Solving for y.
	fw (i, 0, n * 2) {
		if (y[i] <= 1) {
			compressY[1]++;
			ans += (1 - y[i]);
		} else {
			compressY[2]++;
			ans += (y[i] - 2);
		}
	}
	if (compressY[1] > n) ans += compressY[1] - n;
	if (compressY[2] > n) ans += compressY[2] - n;
	//Transferring extra points from 1 to 2 or vice versa.
	fw (i, 0, n * 2) {
		if (x[i] < 1) {
			compressX[1]++;
			ans += (1 - x[i]);
		} else if (x[i] > n) {
			compressX[n]++;
			ans += (x[i] - n);
		} else {
			compressX[x[i]]++;
		}
	}
	int leftmostGoodColumn = 1;
	fw (i, 1, n + 1) {
		while (compressX[i] > 2) {
			while (leftmostGoodColumn <= n && compressX[leftmostGoodColumn] >= 2) leftmostGoodColumn++;
			if (leftmostGoodColumn <= n) {
				compressX[leftmostGoodColumn]++;
				compressX[i]--;
				ans += abs(leftmostGoodColumn - i);
			}
		}
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -