Submission #142785

# Submission time Handle Problem Language Result Execution time Memory
142785 2019-08-11T03:04:29 Z DrumpfTheGodEmperor Coin Collecting (JOI19_ho_t4) C++14
0 / 100
3 ms 376 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");
//	out("ans1.out");
	#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) {
			fw (j, i, n + 1) {
				if (compressX[j] < 2) {
					compressX[j]++;
					compressX[i]--;
					ans += (j - i);
					break;
				}
			}
		}
		while (compressX[i] < 2) {
			fw (j, i, n + 1) {
				if (compressX[j] > 2) {
					compressX[j]--;
					compressX[i]++;
					ans += (j - i);
					break;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:52:6: warning: unused variable 'leftmostGoodColumn' [-Wunused-variable]
  int leftmostGoodColumn = 1;
      ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 3 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 3 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 3 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -