# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211842 | 2020-03-21T14:03:57 Z | DodgeBallMan | Coin Collecting (JOI19_ho_t4) | C++14 | 121 ms | 9056 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1e5 + 10; int n; int coin[N][2]; vector<long> b[2], emp[2]; long ans; int main() { scanf("%d",&n); for( int i = 0, x, y ; i < 2*n ; i++ ) { scanf("%d %d",&x,&y); if( x < 1 ) ans += 1 - x, x = 1; if( x > n ) ans += x - n, x = n; if( y < 1 ) ans += 1 - y, y = 1; if( y > 2 ) ans += y - 2, y = 2; coin[--x][--y]++; } for( int i = 0 ; i < n ; i++ ) for( int j = 0 ; j < 2 ; j++ ) if( !coin[i][j] ) emp[j].emplace_back( i ); sort( emp[0].begin(), emp[0].end(), greater<int>() ), sort( emp[1].begin(), emp[1].end(), greater<int>() ); for( int i = 0 ; i < n ; i++ ) { for( int j = 0 ; j < 2 ; j++ ) if( !b[j].empty() ) { if( coin[i][j] == 0 ) { ans += i - b[j].back(); b[j].pop_back(), emp[j].pop_back(); coin[i][j]++; } if( !coin[i][j^1] && !b[j].empty() && b[j^1].empty() ) { ans += i - b[j].back() + 1; b[j].pop_back(), emp[j^1].pop_back(); coin[i][j^1]++; } } for( int j = 0 ; j < 2 ; j++ ) { while( coin[i][j] > 1 ) { if( !emp[j].empty() && emp[j].back() <= i ) { ans += i - emp[j].back(); emp[j].pop_back(); } else if( !emp[j^1].empty() && emp[1^j].back() <= i ) { if( coin[i][j^1] > 1 ) { coin[i][j^1]--; ans += i - emp[j^1].back(); emp[j^1].pop_back(); continue ; } ans += i - emp[j^1].back() + 1; emp[j^1].pop_back(); } else b[j].emplace_back( i ); coin[i][j]--; } } } printf("%lld",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 256 KB | Output is correct |
10 | Correct | 4 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 4 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 5 ms | 256 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 4 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 256 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 4 ms | 256 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 | 256 KB | Output is correct |
28 | Correct | 4 ms | 256 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 | 256 KB | Output is correct |
32 | Correct | 5 ms | 304 KB | Output is correct |
33 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 256 KB | Output is correct |
10 | Correct | 4 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 4 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 5 ms | 256 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 4 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 256 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 4 ms | 256 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 | 256 KB | Output is correct |
28 | Correct | 4 ms | 256 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 | 256 KB | Output is correct |
32 | Correct | 5 ms | 304 KB | Output is correct |
33 | Correct | 5 ms | 256 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 | 6 ms | 384 KB | Output is correct |
38 | Correct | 6 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 | 4 ms | 384 KB | Output is correct |
43 | Correct | 6 ms | 384 KB | Output is correct |
44 | Correct | 5 ms | 384 KB | Output is correct |
45 | Correct | 6 ms | 384 KB | Output is correct |
46 | Correct | 6 ms | 384 KB | Output is correct |
47 | Correct | 5 ms | 384 KB | Output is correct |
48 | Correct | 6 ms | 384 KB | Output is correct |
49 | Correct | 6 ms | 384 KB | Output is correct |
50 | Correct | 6 ms | 384 KB | Output is correct |
51 | Correct | 6 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 | 6 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 | 6 ms | 384 KB | Output is correct |
63 | Correct | 6 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 | 256 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 256 KB | Output is correct |
10 | Correct | 4 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 4 ms | 256 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 5 ms | 256 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 4 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 256 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 4 ms | 256 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 | 256 KB | Output is correct |
28 | Correct | 4 ms | 256 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 | 256 KB | Output is correct |
32 | Correct | 5 ms | 304 KB | Output is correct |
33 | Correct | 5 ms | 256 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 | 6 ms | 384 KB | Output is correct |
38 | Correct | 6 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 | 4 ms | 384 KB | Output is correct |
43 | Correct | 6 ms | 384 KB | Output is correct |
44 | Correct | 5 ms | 384 KB | Output is correct |
45 | Correct | 6 ms | 384 KB | Output is correct |
46 | Correct | 6 ms | 384 KB | Output is correct |
47 | Correct | 5 ms | 384 KB | Output is correct |
48 | Correct | 6 ms | 384 KB | Output is correct |
49 | Correct | 6 ms | 384 KB | Output is correct |
50 | Correct | 6 ms | 384 KB | Output is correct |
51 | Correct | 6 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 | 6 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 | 6 ms | 384 KB | Output is correct |
63 | Correct | 6 ms | 384 KB | Output is correct |
64 | Correct | 5 ms | 384 KB | Output is correct |
65 | Correct | 54 ms | 2680 KB | Output is correct |
66 | Correct | 81 ms | 9056 KB | Output is correct |
67 | Correct | 80 ms | 5152 KB | Output is correct |
68 | Correct | 82 ms | 5236 KB | Output is correct |
69 | Correct | 83 ms | 5236 KB | Output is correct |
70 | Correct | 81 ms | 5236 KB | Output is correct |
71 | Correct | 81 ms | 5400 KB | Output is correct |
72 | Correct | 71 ms | 7140 KB | Output is correct |
73 | Correct | 76 ms | 5476 KB | Output is correct |
74 | Correct | 85 ms | 7172 KB | Output is correct |
75 | Correct | 79 ms | 6888 KB | Output is correct |
76 | Correct | 76 ms | 7012 KB | Output is correct |
77 | Correct | 77 ms | 5988 KB | Output is correct |
78 | Correct | 79 ms | 6884 KB | Output is correct |
79 | Correct | 77 ms | 5604 KB | Output is correct |
80 | Correct | 84 ms | 5620 KB | Output is correct |
81 | Correct | 83 ms | 6884 KB | Output is correct |
82 | Correct | 83 ms | 5860 KB | Output is correct |
83 | Correct | 77 ms | 5732 KB | Output is correct |
84 | Correct | 84 ms | 6244 KB | Output is correct |
85 | Correct | 121 ms | 5988 KB | Output is correct |
86 | Correct | 79 ms | 6124 KB | Output is correct |
87 | Correct | 79 ms | 5996 KB | Output is correct |
88 | Correct | 88 ms | 5996 KB | Output is correct |
89 | Correct | 81 ms | 6120 KB | Output is correct |
90 | Correct | 86 ms | 5612 KB | Output is correct |
91 | Correct | 79 ms | 5524 KB | Output is correct |
92 | Correct | 82 ms | 5612 KB | Output is correct |
93 | Correct | 78 ms | 5616 KB | Output is correct |
94 | Correct | 85 ms | 5488 KB | Output is correct |
95 | Correct | 79 ms | 5488 KB | Output is correct |
96 | Correct | 75 ms | 5740 KB | Output is correct |
97 | Correct | 74 ms | 5740 KB | Output is correct |
98 | Correct | 77 ms | 7276 KB | Output is correct |
99 | Correct | 78 ms | 6116 KB | Output is correct |
100 | Correct | 85 ms | 6504 KB | Output is correct |
101 | Correct | 76 ms | 5992 KB | Output is correct |
102 | Correct | 80 ms | 7256 KB | Output is correct |
103 | Correct | 96 ms | 7148 KB | Output is correct |