Submission #220184

# Submission time Handle Problem Language Result Execution time Memory
220184 2020-04-07T08:53:39 Z anatolik Coin Collecting (JOI19_ho_t4) C++14
0 / 100
5 ms 384 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#define ll long long

using namespace std;

void gen() {

}

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];
	}
	ll val2 = 2 * n - val;
	ll need = val - n;
	for (int i = 0; i < n; i++) {
		if (need == 0)
			break;
		if (need > 0) {
			ll x = min(need, (ll)a[i]);
			b[i] += x;
			need -= x;
			a[i] -= x;
			S += x;
			continue;
		}
		if (need < 0) {
			ll x = min(-need, (ll)b[i]);
			a[i] += x;
			need += x;
			b[i] -= x;
			S += x;
			continue;
		}
	}
	//ll need = abs(val - n);
	//S += need;
	ll now1 = 0, now2 = 0;
	for (int i = 0; i < n; i++) {
		now1 += a[i];
		now2 += b[i];
		S += abs(now1 - (i + 1));
		S += abs(now2 - (i + 1));
	}
	cout << S << endl;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:50:5: warning: unused variable 'val2' [-Wunused-variable]
  ll val2 = 2 * n - val;
     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -