#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
const int N = 1e5+12;
int n, used[N][4];
long long ans = 0;
int main(){
cin >> n;
for(int i = 1; i <= 2 * n; ++i){
int x, y;
cin >> x >> y;
if(y > 2){
ans += y - 2;
y = 2;
}
if(y < 1){
ans += abs(y-1);
y = 1;
}
if(x > n){
ans += x - n;
x = n;
}
if(x < 1){
ans += abs(x-1);
x = 1;
}
++used[x][y];
}
int cnt1 = 0, cnt2 = 0;
for(int i = 1; i <= n; ++i){
cnt1 += used[i][1] - 1;
cnt2 += used[i][2] - 1;
int mn = min(abs(cnt1), abs(cnt2));
if(cnt1 < 0 && cnt2 > 0){
cnt1 += mn;
cnt2 -= mn;
ans += mn;
}else if(cnt1 > 0 && cnt2 < 0){
cnt2 += mn;
cnt1 -= mn;
ans += mn;
}
ans += abs(cnt1) + abs(cnt2);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
2 ms |
204 KB |
Output is correct |
35 |
Correct |
4 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
316 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
324 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
2 ms |
332 KB |
Output is correct |
47 |
Correct |
2 ms |
336 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
336 KB |
Output is correct |
50 |
Correct |
3 ms |
340 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
3 ms |
332 KB |
Output is correct |
53 |
Correct |
2 ms |
312 KB |
Output is correct |
54 |
Correct |
3 ms |
332 KB |
Output is correct |
55 |
Correct |
2 ms |
312 KB |
Output is correct |
56 |
Correct |
2 ms |
316 KB |
Output is correct |
57 |
Correct |
2 ms |
312 KB |
Output is correct |
58 |
Correct |
2 ms |
332 KB |
Output is correct |
59 |
Correct |
2 ms |
332 KB |
Output is correct |
60 |
Correct |
2 ms |
332 KB |
Output is correct |
61 |
Correct |
2 ms |
332 KB |
Output is correct |
62 |
Correct |
2 ms |
312 KB |
Output is correct |
63 |
Correct |
3 ms |
308 KB |
Output is correct |
64 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
2 ms |
204 KB |
Output is correct |
35 |
Correct |
4 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
316 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
324 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
2 ms |
332 KB |
Output is correct |
47 |
Correct |
2 ms |
336 KB |
Output is correct |
48 |
Correct |
2 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
336 KB |
Output is correct |
50 |
Correct |
3 ms |
340 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
3 ms |
332 KB |
Output is correct |
53 |
Correct |
2 ms |
312 KB |
Output is correct |
54 |
Correct |
3 ms |
332 KB |
Output is correct |
55 |
Correct |
2 ms |
312 KB |
Output is correct |
56 |
Correct |
2 ms |
316 KB |
Output is correct |
57 |
Correct |
2 ms |
312 KB |
Output is correct |
58 |
Correct |
2 ms |
332 KB |
Output is correct |
59 |
Correct |
2 ms |
332 KB |
Output is correct |
60 |
Correct |
2 ms |
332 KB |
Output is correct |
61 |
Correct |
2 ms |
332 KB |
Output is correct |
62 |
Correct |
2 ms |
312 KB |
Output is correct |
63 |
Correct |
3 ms |
308 KB |
Output is correct |
64 |
Correct |
2 ms |
332 KB |
Output is correct |
65 |
Correct |
111 ms |
3352 KB |
Output is correct |
66 |
Correct |
243 ms |
4964 KB |
Output is correct |
67 |
Correct |
168 ms |
5016 KB |
Output is correct |
68 |
Correct |
167 ms |
5020 KB |
Output is correct |
69 |
Correct |
154 ms |
5016 KB |
Output is correct |
70 |
Correct |
154 ms |
5016 KB |
Output is correct |
71 |
Correct |
141 ms |
5024 KB |
Output is correct |
72 |
Correct |
134 ms |
3476 KB |
Output is correct |
73 |
Correct |
135 ms |
3480 KB |
Output is correct |
74 |
Correct |
135 ms |
3552 KB |
Output is correct |
75 |
Correct |
135 ms |
3272 KB |
Output is correct |
76 |
Correct |
132 ms |
3476 KB |
Output is correct |
77 |
Correct |
136 ms |
3524 KB |
Output is correct |
78 |
Correct |
135 ms |
3396 KB |
Output is correct |
79 |
Correct |
145 ms |
3472 KB |
Output is correct |
80 |
Correct |
132 ms |
3480 KB |
Output is correct |
81 |
Correct |
132 ms |
3484 KB |
Output is correct |
82 |
Correct |
154 ms |
3500 KB |
Output is correct |
83 |
Correct |
135 ms |
3396 KB |
Output is correct |
84 |
Correct |
131 ms |
3756 KB |
Output is correct |
85 |
Correct |
136 ms |
3832 KB |
Output is correct |
86 |
Correct |
133 ms |
4924 KB |
Output is correct |
87 |
Correct |
133 ms |
4856 KB |
Output is correct |
88 |
Correct |
137 ms |
5020 KB |
Output is correct |
89 |
Correct |
138 ms |
5020 KB |
Output is correct |
90 |
Correct |
138 ms |
5024 KB |
Output is correct |
91 |
Correct |
144 ms |
5016 KB |
Output is correct |
92 |
Correct |
149 ms |
5020 KB |
Output is correct |
93 |
Correct |
141 ms |
5096 KB |
Output is correct |
94 |
Correct |
142 ms |
4888 KB |
Output is correct |
95 |
Correct |
140 ms |
4920 KB |
Output is correct |
96 |
Correct |
180 ms |
4540 KB |
Output is correct |
97 |
Correct |
145 ms |
4492 KB |
Output is correct |
98 |
Correct |
138 ms |
4380 KB |
Output is correct |
99 |
Correct |
143 ms |
4180 KB |
Output is correct |
100 |
Correct |
144 ms |
4200 KB |
Output is correct |
101 |
Correct |
143 ms |
4404 KB |
Output is correct |
102 |
Correct |
135 ms |
4240 KB |
Output is correct |
103 |
Correct |
163 ms |
4164 KB |
Output is correct |