Submission #316279

# Submission time Handle Problem Language Result Execution time Memory
316279 2020-10-25T19:02:56 Z shrek12357 Coin Collecting (JOI19_ho_t4) C++14
100 / 100
403 ms 6000 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0); 

int main() {
	int n;
	cin >> n;
	vector<int> v1, v2;
	ll ans = 0;
	for (int i = 0; i < 2*n; i++) {
		ll a, b;
		cin >> a >> b;
		if (b >= 2) {
			ans += b - 2;
			b = 2;
		}
		else {
			ans += 1 - b;
			b = 1;
		}
		if (a >= n) {
			ans += a - n;
			a = n;
		}
		else if (a <= 1) {
			ans += 1 - a;
			a = 1;
		}
		if (b == 1) {
			v1.push_back(a);
		}
		else {
			v2.push_back(a);
		}
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	queue<ll> q1, q2;
	int idx1 = 0, idx2 = 0;
	for (int i = 1; i <= n; i++) {
		q1.push(i);
		q2.push(i);
		while (q1.size() > 0 && idx1 < v1.size() && v1[idx1] <= i) {
			ans += abs(q1.front() - v1[idx1]);
			idx1++;
			q1.pop();
		}
		while (q2.size() > 0 && idx2 < v2.size() && v2[idx2] <= i) {
			ans += abs(q2.front() - v2[idx2]);
			idx2++;
			q2.pop();
		}
		while (q2.size() > 0 && idx1 < v1.size() && v1[idx1] <= i) {
			ans += abs(q2.front() - v1[idx1]) + 1;
			idx1++;
			q2.pop();	
		}
		while (q1.size() > 0 && idx2 < v2.size() && v2[idx2] <= i) {
			ans += abs(q1.front() - v2[idx2]) + 1;
			idx2++;
			q1.pop();
		}
	}
	cout << ans << endl;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:55:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   while (q1.size() > 0 && idx1 < v1.size() && v1[idx1] <= i) {
      |                           ~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:60:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   while (q2.size() > 0 && idx2 < v2.size() && v2[idx2] <= i) {
      |                           ~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:65:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   while (q2.size() > 0 && idx1 < v1.size() && v1[idx1] <= i) {
      |                           ~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:70:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   while (q1.size() > 0 && idx2 < v2.size() && v2[idx2] <= i) {
      |                           ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 3 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 3 ms 384 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 3 ms 384 KB Output is correct
64 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 3 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 3 ms 384 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 3 ms 384 KB Output is correct
64 Correct 3 ms 384 KB Output is correct
65 Correct 184 ms 3048 KB Output is correct
66 Correct 403 ms 6000 KB Output is correct
67 Correct 305 ms 4696 KB Output is correct
68 Correct 305 ms 4584 KB Output is correct
69 Correct 306 ms 4588 KB Output is correct
70 Correct 304 ms 4484 KB Output is correct
71 Correct 305 ms 4588 KB Output is correct
72 Correct 293 ms 4844 KB Output is correct
73 Correct 295 ms 5812 KB Output is correct
74 Correct 295 ms 4588 KB Output is correct
75 Correct 285 ms 4524 KB Output is correct
76 Correct 293 ms 4724 KB Output is correct
77 Correct 290 ms 5012 KB Output is correct
78 Correct 295 ms 4716 KB Output is correct
79 Correct 298 ms 4840 KB Output is correct
80 Correct 298 ms 4972 KB Output is correct
81 Correct 295 ms 4728 KB Output is correct
82 Correct 294 ms 4560 KB Output is correct
83 Correct 297 ms 4772 KB Output is correct
84 Correct 297 ms 4376 KB Output is correct
85 Correct 298 ms 4524 KB Output is correct
86 Correct 298 ms 4396 KB Output is correct
87 Correct 302 ms 4460 KB Output is correct
88 Correct 304 ms 4396 KB Output is correct
89 Correct 306 ms 4588 KB Output is correct
90 Correct 309 ms 4584 KB Output is correct
91 Correct 304 ms 4460 KB Output is correct
92 Correct 317 ms 4732 KB Output is correct
93 Correct 313 ms 4460 KB Output is correct
94 Correct 298 ms 4472 KB Output is correct
95 Correct 297 ms 4332 KB Output is correct
96 Correct 339 ms 5484 KB Output is correct
97 Correct 338 ms 5476 KB Output is correct
98 Correct 298 ms 4720 KB Output is correct
99 Correct 302 ms 5236 KB Output is correct
100 Correct 305 ms 4840 KB Output is correct
101 Correct 328 ms 5240 KB Output is correct
102 Correct 303 ms 4560 KB Output is correct
103 Correct 302 ms 4584 KB Output is correct