Submission #229500

# Submission time Handle Problem Language Result Execution time Memory
229500 2020-05-04T19:57:12 Z hanagasumi Coin Collecting (JOI19_ho_t4) C++17
100 / 100
91 ms 10484 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>

#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll

using namespace std;
typedef long long ll;

int sgn(int x) {
	if(x < 0) 
		return -1;
	if(x == 0) 
		return 0;
	return 1;
}

signed main() {
	#ifdef PC
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	vector<vector<int>> have(n, vector<int> (2, 0));
	int ans = 0;
	for (int i = 0; i < 2 * n; i++) {
		int x, y;
		cin >> x >> y;
		if(y < 1) 
			ans += (1 - y), y = 1;
		if(y > 2) 
			ans += (y - 2), y = 2;
		if(x < 1) 
			ans += (1 - x), x = 1;
		if(x > n) 
			ans += (x - n), x = n;
		have[x - 1][y - 1]++;
	}

	// for (int j = 0; j < 2; j++) {
	// 	for (int i = 0; i < n; i++) {
	// 		cout << have[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	// cout << ans << endl;
	// ans = 0;
	int top = 0, down = 0;
	for (int i = 0; i < n; i++) {
		top += have[i][0], down += have[i][1];
		top--, down--;
		// cout << i << " " << ans << "  " << top << " " << down << endl;
		if(top * down < 0) {
			int per = min(abs(top), abs(down));
			top += -1 * sgn(top) * per;
			down += -1 * sgn(down) * per;
			ans += per;
		}
		ans += abs(top) + abs(down);
	}
	cout << ans << '\n';
}

/*
if(have[i][0] == 0) {

			for (int j = i + 1; j < n; j++) {
				if(have[j][0] > 1) {
					cout << "X  " << i << " " << j << endl; 
					have[j][0]--;
					ans += (j - i);
					have[i][0] = 1;
					break;
				}
				if(j == i + 1 && down != 0) {
					down--;
					ans += 1;
					have[i][0] = 1;
					break;
				}
				if(have[j - 1][1] > 1) {
					have[j - 1][1]--;
					ans += (j - i);
					have[i][0] = 1;
					break;
				}
			}
			if(have[i][0] == 0) {
				ans += (n - i);
				have[i][0] = 1;
				if(i != n - 1)
					have[n - 1][1]--;
			}
			
		}
		if(have[i][1] == 0) {
			for (int j = i + 1; j < n; j++) {
				if(have[j][1] > 1) {
					have[j][1]--;
					ans += (j - i);
					have[i][1] = 1;
					break;
				}
				if(j == i + 1 && top != 0) {
					top--;
					ans += 1;
					have[i][1] = 1;
					break;
				}
				if(have[j - 1][0] > 1) {
					have[j - 1][0]--;
					ans += (j - i);
					have[i][1] = 1;
					break;
				}
			}
			if(have[i][1] == 0) {
				have[i][1] = 1;
				ans += (n - i);
				if(i != n - 1)
					have[n - 1][0]--;
			}
		}
		if(i == n - 1) 
			break;
		ans += top + down;
	}
	*/
# Verdict Execution time Memory Grader output
1 Correct 4 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 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 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 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 6 ms 384 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 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 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 6 ms 384 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 68 ms 7416 KB Output is correct
66 Correct 82 ms 10484 KB Output is correct
67 Correct 77 ms 8952 KB Output is correct
68 Correct 75 ms 8952 KB Output is correct
69 Correct 88 ms 9080 KB Output is correct
70 Correct 81 ms 9080 KB Output is correct
71 Correct 83 ms 9080 KB Output is correct
72 Correct 69 ms 9084 KB Output is correct
73 Correct 66 ms 9080 KB Output is correct
74 Correct 67 ms 9080 KB Output is correct
75 Correct 70 ms 8952 KB Output is correct
76 Correct 68 ms 9080 KB Output is correct
77 Correct 67 ms 8952 KB Output is correct
78 Correct 67 ms 9084 KB Output is correct
79 Correct 70 ms 9080 KB Output is correct
80 Correct 67 ms 9208 KB Output is correct
81 Correct 68 ms 9080 KB Output is correct
82 Correct 68 ms 9208 KB Output is correct
83 Correct 67 ms 9080 KB Output is correct
84 Correct 66 ms 9080 KB Output is correct
85 Correct 67 ms 8944 KB Output is correct
86 Correct 70 ms 8952 KB Output is correct
87 Correct 76 ms 9080 KB Output is correct
88 Correct 71 ms 9080 KB Output is correct
89 Correct 72 ms 8952 KB Output is correct
90 Correct 76 ms 8956 KB Output is correct
91 Correct 79 ms 8952 KB Output is correct
92 Correct 78 ms 9208 KB Output is correct
93 Correct 91 ms 9212 KB Output is correct
94 Correct 81 ms 8952 KB Output is correct
95 Correct 89 ms 8952 KB Output is correct
96 Correct 68 ms 9080 KB Output is correct
97 Correct 70 ms 9080 KB Output is correct
98 Correct 74 ms 9080 KB Output is correct
99 Correct 71 ms 9080 KB Output is correct
100 Correct 69 ms 9072 KB Output is correct
101 Correct 69 ms 9080 KB Output is correct
102 Correct 71 ms 9080 KB Output is correct
103 Correct 71 ms 9080 KB Output is correct