Submission #220746

# Submission time Handle Problem Language Result Execution time Memory
220746 2020-04-08T14:54:03 Z DmitryGrigorev Coin Collecting (JOI19_ho_t4) C++14
100 / 100
69 ms 6008 KB
#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

int sum[100007][3];

vector<pair<int, int> > calc(vector<pair<int, int> > v, int &ans) {
	vector<pair<int, int> > res;
	for (int i = 0; i < v.size(); ++i) {
		if (res.size() && res.back().second%2 != v[i].second%2) {
			ans += abs(res.back().first - v[i].first) + abs(res.back().second/2 - v[i].first/2) ;
			res.pop_back();
		}
		else res.push_back(v[i]);
	}

	return res;
}

main(){
#ifdef LOCAL
	freopen("N_input.txt", "r", stdin);
	//freopen("N_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	int ans = 0;

	for (int i = 0; i < 2*n; ++i) {
		int x, y;
		cin >> x >> y;

		int z, t;
		if (x <= 0) z = 1;
		else if (x > n) z = n;
		else z = x;

		if (y <= 1) t = 1;
		else t = 2;

		ans += abs(x-z) + abs(y-t);

		sum[z][t]++;
	}

	int wa = 0, wb = 0;
	for (int i = 0; i < n; ++i) {
		//cout << wa << " " << wb << endl;
		int A = sum[i+1][1] - 1, B = sum[i+1][2] - 1;

		//cout << "== " << A << " " << B << endl;

		while (A < 0 && wa > 0) {
			A++, wa--;
		}

		while (A > 0 && wa < 0) {
			A--, wa++;
		}

		while (B < 0 && wb > 0) {
			B++, wb--;
		}

		while (B > 0 && wb < 0) {
			B--, wb++;
		}

		while (A > 0 && B < 0) {
			ans++, A--, B++;
		}

		while (A < 0 && B > 0) {
			ans++, A++, B--;
		}


		while (A < 0 && wb > 0) {
			A++, wb--;
			ans++;
		}

		while (A > 0 && wb < 0) {
			A--, wb++;
			ans++;
		}

		while (B < 0 && wa > 0) {
			B++, wa--;
			ans++;
		}

		while (B > 0 && wa < 0) {
			B--, wa++;
			ans++;
		}

		wa+=A, wb+=B;
		ans += abs(wa) + abs(wb);





	}
	cout << ans;

}

Compilation message

joi2019_ho_t4.cpp: In function 'std::vector<std::pair<long long int, long long int> > calc(std::vector<std::pair<long long int, long long int> >, long long int&)':
joi2019_ho_t4.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); ++i) {
                  ~~^~~~~~~~~~
joi2019_ho_t4.cpp: At global scope:
joi2019_ho_t4.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 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 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 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 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 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 6 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 5 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 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 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 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 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 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 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 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 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 6 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 5 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 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 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 5 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 9 ms 384 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 6 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 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 384 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 512 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 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 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 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 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 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 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 6 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 5 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 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 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 5 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 9 ms 384 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 6 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 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 384 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 512 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 47 ms 4216 KB Output is correct
66 Correct 69 ms 4984 KB Output is correct
67 Correct 62 ms 5880 KB Output is correct
68 Correct 63 ms 5880 KB Output is correct
69 Correct 59 ms 5880 KB Output is correct
70 Correct 61 ms 6008 KB Output is correct
71 Correct 67 ms 5880 KB Output is correct
72 Correct 56 ms 3576 KB Output is correct
73 Correct 58 ms 3576 KB Output is correct
74 Correct 57 ms 3576 KB Output is correct
75 Correct 62 ms 3572 KB Output is correct
76 Correct 56 ms 3576 KB Output is correct
77 Correct 60 ms 3448 KB Output is correct
78 Correct 58 ms 3576 KB Output is correct
79 Correct 61 ms 3576 KB Output is correct
80 Correct 59 ms 3576 KB Output is correct
81 Correct 57 ms 3576 KB Output is correct
82 Correct 55 ms 3576 KB Output is correct
83 Correct 56 ms 3576 KB Output is correct
84 Correct 60 ms 3960 KB Output is correct
85 Correct 67 ms 3960 KB Output is correct
86 Correct 60 ms 5496 KB Output is correct
87 Correct 57 ms 5496 KB Output is correct
88 Correct 61 ms 5884 KB Output is correct
89 Correct 58 ms 5880 KB Output is correct
90 Correct 62 ms 5880 KB Output is correct
91 Correct 64 ms 5880 KB Output is correct
92 Correct 59 ms 6008 KB Output is correct
93 Correct 64 ms 6008 KB Output is correct
94 Correct 57 ms 5752 KB Output is correct
95 Correct 59 ms 5752 KB Output is correct
96 Correct 58 ms 5240 KB Output is correct
97 Correct 60 ms 5112 KB Output is correct
98 Correct 59 ms 4996 KB Output is correct
99 Correct 61 ms 4600 KB Output is correct
100 Correct 60 ms 4600 KB Output is correct
101 Correct 59 ms 4984 KB Output is correct
102 Correct 60 ms 4728 KB Output is correct
103 Correct 62 ms 4600 KB Output is correct