# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
162480 | 2019-11-08T10:47:35 Z | pink_bittern | Coin Collecting (JOI19_ho_t4) | C++14 | 75 ms | 11436 KB |
#include <bits/stdc++.h> #define pb push_back #define pll pair <ll, ll> #define MOMI using namespace std; #define mp make_pair #define pvb pair <vector <pll>, bool> #define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); #pragma optimize("TKACHENKO-GORYACHENKO") // #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") typedef long long ll; typedef long double ld; using namespace std; const ll maxn = 5e5; ll n, m, k; ll X[maxn]; ll Y[maxn]; ll A[maxn][2]; ll ans = 0; vector <ll> P[2]; vector <ll> M[2]; void add(ll i) { ll x, y; if (Y[i] >= 2) { y = 2; // ans += Y[i] - 2; } else { y = 1; // ans += 1 - Y[i]; } if (X[i] < 1) { x = 1; } else { if (X[i] > n) { x = n; } else { x = X[i]; } } // cout << "DX " << X[i] - x << " " << " DY " << Y[i] - y << endl; ans += abs(X[i] - x) + abs(Y[i] - y); A[x - 1][y - 1]++; } signed main() { ll q, w, e, a, b, c, d; pyshnapyshnakaa; cin >> n; for (q = 0; q < 2 * n; q++) { cin >> X[q] >> Y[q]; add(q); } // cout << ans << " PREANS" << endl; for (q = 0; q < n; q++) { for (w = 0; w < 2; w++) { while (A[q][w] > 1) { // cout << q << if (!M[w].empty()) { ll i = M[w].back(); M[w].pop_back(); ans += q - i; // cout << "TYPE 0" << endl; A[q][w]--; } else { P[w].pb(q); // break; A[q][w]--; } } while (A[q][w] < 1) { // cout << q << " Q" << endl; if (!P[w].empty()) { ll i = P[w].back(); P[w].pop_back(); ans += q - i; // cout << "TYPE 1" << endl; A[q][w]++; } else { M[w].pb(q); break; } } } for (w = 0; w < 2; w++) { while (!P[w].empty() && !M[1 - w].empty()) { ll i = P[w].back(), j = M[1 - w].back(); P[w].pop_back(); M[1 - w].pop_back(); ans += abs(i - j) + 1; // cout << "TYPE 2 " << i << " " << j << endl; } } } cout << ans; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 248 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 13 ms | 380 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 376 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 2 ms | 376 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 2 ms | 376 KB | Output is correct |
32 | Correct | 2 ms | 376 KB | Output is correct |
33 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 248 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 13 ms | 380 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 376 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 2 ms | 376 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 2 ms | 376 KB | Output is correct |
32 | Correct | 2 ms | 376 KB | Output is correct |
33 | Correct | 2 ms | 376 KB | Output is correct |
34 | Correct | 2 ms | 376 KB | Output is correct |
35 | Correct | 3 ms | 504 KB | Output is correct |
36 | Correct | 3 ms | 504 KB | Output is correct |
37 | Correct | 3 ms | 516 KB | Output is correct |
38 | Correct | 3 ms | 376 KB | Output is correct |
39 | Correct | 3 ms | 376 KB | Output is correct |
40 | Correct | 3 ms | 504 KB | Output is correct |
41 | Correct | 3 ms | 504 KB | Output is correct |
42 | Correct | 3 ms | 504 KB | Output is correct |
43 | Correct | 3 ms | 376 KB | Output is correct |
44 | Correct | 3 ms | 424 KB | Output is correct |
45 | Correct | 3 ms | 504 KB | Output is correct |
46 | Correct | 3 ms | 504 KB | Output is correct |
47 | Correct | 3 ms | 376 KB | Output is correct |
48 | Correct | 3 ms | 504 KB | Output is correct |
49 | Correct | 3 ms | 436 KB | Output is correct |
50 | Correct | 3 ms | 376 KB | Output is correct |
51 | Correct | 3 ms | 376 KB | Output is correct |
52 | Correct | 3 ms | 376 KB | Output is correct |
53 | Correct | 3 ms | 504 KB | Output is correct |
54 | Correct | 3 ms | 376 KB | Output is correct |
55 | Correct | 3 ms | 376 KB | Output is correct |
56 | Correct | 2 ms | 376 KB | Output is correct |
57 | Correct | 3 ms | 504 KB | Output is correct |
58 | Correct | 3 ms | 504 KB | Output is correct |
59 | Correct | 3 ms | 504 KB | Output is correct |
60 | Correct | 3 ms | 504 KB | Output is correct |
61 | Correct | 3 ms | 376 KB | Output is correct |
62 | Correct | 3 ms | 504 KB | Output is correct |
63 | Correct | 3 ms | 504 KB | Output is correct |
64 | Correct | 3 ms | 504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 248 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 13 ms | 380 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 376 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 2 ms | 376 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 2 ms | 376 KB | Output is correct |
32 | Correct | 2 ms | 376 KB | Output is correct |
33 | Correct | 2 ms | 376 KB | Output is correct |
34 | Correct | 2 ms | 376 KB | Output is correct |
35 | Correct | 3 ms | 504 KB | Output is correct |
36 | Correct | 3 ms | 504 KB | Output is correct |
37 | Correct | 3 ms | 516 KB | Output is correct |
38 | Correct | 3 ms | 376 KB | Output is correct |
39 | Correct | 3 ms | 376 KB | Output is correct |
40 | Correct | 3 ms | 504 KB | Output is correct |
41 | Correct | 3 ms | 504 KB | Output is correct |
42 | Correct | 3 ms | 504 KB | Output is correct |
43 | Correct | 3 ms | 376 KB | Output is correct |
44 | Correct | 3 ms | 424 KB | Output is correct |
45 | Correct | 3 ms | 504 KB | Output is correct |
46 | Correct | 3 ms | 504 KB | Output is correct |
47 | Correct | 3 ms | 376 KB | Output is correct |
48 | Correct | 3 ms | 504 KB | Output is correct |
49 | Correct | 3 ms | 436 KB | Output is correct |
50 | Correct | 3 ms | 376 KB | Output is correct |
51 | Correct | 3 ms | 376 KB | Output is correct |
52 | Correct | 3 ms | 376 KB | Output is correct |
53 | Correct | 3 ms | 504 KB | Output is correct |
54 | Correct | 3 ms | 376 KB | Output is correct |
55 | Correct | 3 ms | 376 KB | Output is correct |
56 | Correct | 2 ms | 376 KB | Output is correct |
57 | Correct | 3 ms | 504 KB | Output is correct |
58 | Correct | 3 ms | 504 KB | Output is correct |
59 | Correct | 3 ms | 504 KB | Output is correct |
60 | Correct | 3 ms | 504 KB | Output is correct |
61 | Correct | 3 ms | 376 KB | Output is correct |
62 | Correct | 3 ms | 504 KB | Output is correct |
63 | Correct | 3 ms | 504 KB | Output is correct |
64 | Correct | 3 ms | 504 KB | Output is correct |
65 | Correct | 47 ms | 6648 KB | Output is correct |
66 | Correct | 75 ms | 11436 KB | Output is correct |
67 | Correct | 71 ms | 8312 KB | Output is correct |
68 | Correct | 70 ms | 8312 KB | Output is correct |
69 | Correct | 73 ms | 8312 KB | Output is correct |
70 | Correct | 68 ms | 8300 KB | Output is correct |
71 | Correct | 71 ms | 8312 KB | Output is correct |
72 | Correct | 64 ms | 9444 KB | Output is correct |
73 | Correct | 62 ms | 8488 KB | Output is correct |
74 | Correct | 62 ms | 9328 KB | Output is correct |
75 | Correct | 64 ms | 9156 KB | Output is correct |
76 | Correct | 63 ms | 9332 KB | Output is correct |
77 | Correct | 63 ms | 8412 KB | Output is correct |
78 | Correct | 62 ms | 9264 KB | Output is correct |
79 | Correct | 64 ms | 8048 KB | Output is correct |
80 | Correct | 61 ms | 7884 KB | Output is correct |
81 | Correct | 63 ms | 9136 KB | Output is correct |
82 | Correct | 61 ms | 8184 KB | Output is correct |
83 | Correct | 60 ms | 8052 KB | Output is correct |
84 | Correct | 62 ms | 8568 KB | Output is correct |
85 | Correct | 62 ms | 8312 KB | Output is correct |
86 | Correct | 61 ms | 8312 KB | Output is correct |
87 | Correct | 62 ms | 8312 KB | Output is correct |
88 | Correct | 66 ms | 8312 KB | Output is correct |
89 | Correct | 64 ms | 8284 KB | Output is correct |
90 | Correct | 69 ms | 8312 KB | Output is correct |
91 | Correct | 65 ms | 8312 KB | Output is correct |
92 | Correct | 70 ms | 8312 KB | Output is correct |
93 | Correct | 71 ms | 8316 KB | Output is correct |
94 | Correct | 74 ms | 8184 KB | Output is correct |
95 | Correct | 69 ms | 8184 KB | Output is correct |
96 | Correct | 67 ms | 9828 KB | Output is correct |
97 | Correct | 67 ms | 9592 KB | Output is correct |
98 | Correct | 68 ms | 9580 KB | Output is correct |
99 | Correct | 67 ms | 8940 KB | Output is correct |
100 | Correct | 67 ms | 9176 KB | Output is correct |
101 | Correct | 65 ms | 9708 KB | Output is correct |
102 | Correct | 67 ms | 9692 KB | Output is correct |
103 | Correct | 67 ms | 10092 KB | Output is correct |