Submission #496820

# Submission time Handle Problem Language Result Execution time Memory
496820 2021-12-22T04:50:12 Z Mukhitali Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 332 KB
//bit chass 1
#include <bits/stdc++.h>

#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;

const int N = 2e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;

ll c[3][N];

void solve() {
	ll n;
	ll ans = 0;
	cin >> n;
	for (int i = 1; i <= 2 * n; i++) {
		ll x, y;
		cin >> x >> y;
		if (1 <= x && x <= n && 1 <= y && y <= 2)
			c[y][x]++;
		else if (1 <= x && x <= n) {
			if (y <= 0) 
				c[1][x]++, ans += 1 - y;
			else 
				c[2][x]++, ans += y - 2;
		}
		else if (1 <= y && y <= 2) {
			if (x <= 0) 
				c[y][1]++, ans += 1 - x;
			else  
				c[y][n]++, ans += x - n;
		}
		else {
			if (x <= 0 && y <= 0) 
				c[1][1]++, ans += 1 - y + 1 - x;
			if (x <= 0 && y > 2)
				c[2][1]++, ans += 1 - x + y - 2;
			if (x > n && y <= 0)
				c[1][n]++, ans += x - n + 1 - y;
			if (x > n && y > 2)
				c[2][n]++, ans += x - n + y - 2;
		}
	}
//	cout << ans  << el;
//	for (int i = 2; i >= 1; i--) {
//		for (int j = 1; j <= n; j++)
//			cout << c[i][j] << ' ';
//		cout << el;
//	}
	int r = 1;
	for (int i = 1; i <= n; i++) {
		r = max(i, r);
		if (c[1][i] && c[2][i]) {
			c[1][i]--;
			c[2][i]--;
			ans += c[1][i];
			ans += c[2][i];
			c[1][i + 1] += c[1][i];
			c[2][i + 1] += c[2][i];
		}
		else if (c[1][i]) {
			if (c[1][i] >= 2) {
				c[2][i]++;
				ans++;
				c[1][i] -= 2;
				c[1][i + 1] += c[1][i];
				ans += c[1][i];
			}
			else {
				r = max(r, i + 1);
				while (c[1][r] + c[2][r] == 0)
					r++;
				if (c[2][r]) {
					ans += r - i;
					c[2][r]--;
					c[2][i]++;
				}
				else {
					ans += r - i + 1;
					c[1][r]--;
					c[2][i]++;
				}
			}
		}
		else if (c[2][i]) {
			if (c[2][i] >= 2) {
				c[1][i]++;
				ans++;
				c[2][i] -= 2;
				c[2][i + 1] += c[2][i];
				ans += c[2][i];
			}
			else {
				r = max(r, i + 1);
				while (c[1][r] + c[2][r] == 0)
					r++;
				if (c[1][r]) {
					ans += r - i;
					c[1][i]++;
					c[1][r]--;
				}
				else {
					ans += r - i + 1;
					c[2][r]--;
					c[1][i]++;
				}
			}
		}
		else {
			while (c[1][r] + c[2][r] == 0) 
				r++;
			if (c[1][r]) {
				c[1][i]++;
				ans += r - i;
				c[1][r]--;
				if (c[2][r]) {
					c[2][i]++;
					ans += r - i;
					c[2][r]--;	
				}
				else {
					while (c[1][r] + c[2][r] == 0)
						r++;
					if (c[2][r]) {
						ans += r - i;
						c[2][r]--;
						c[2][i]++;
					}
					else {
						ans += r - i + 1;
						c[1][r]--;
						c[2][i]++;
					}
				}
			}
			else if (c[2][r]) {
				c[2][i]++;
				ans += r - i;
				c[2][r]--;
				if (c[1][r]) {
					c[1][i]++;
					ans += r - i;
					c[1][r]--;	
				}
				else {
					while (c[1][r] + c[2][r] == 0)
						r++;
					if (c[1][r]) {
						ans += r - i;
						c[1][i]++;
						c[1][r]--;
					}
					else {
						ans += r - i + 1;
						c[2][r]--;
						c[1][i]++;
					}
				}
			}
		}
	}
	cout << ans;
}

int main() {
	ibase;
	int T = 1;
//	cin >> T;
	for (int i = 1; i <= T; i++) {
//		cout << "Case " << i << ": ";
		solve();
		cout << el;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -