//çalışan kazanır//
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
int gcd (int a, int b) {if (b == 0){return a;}else {return gcd (b, a % b);}}
const int N = 4e5 + 15;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MODD = 1070234587ll;
const double eps = 0.0001;
const int p = 87;
int n, x[N], y[N];
int cnt[N][3], dp[2001][2001];
void solution () {
cin >> n;
for (int i = 1; i <= n * 2; ++ i) cin >> x[i] >> y[i];
int res = 0;
for (int i = 1; i <= n * 2; ++ i) {
if (1 <= x[i] && x[i] <= n) {
if (1 <= y[i] && y[i] <= 2) cnt[x[i]][y[i]] ++;
if (y[i] < 1) cnt[x[i]][1] ++, res += (1 - y[i]), y[i] = 1;
if (2 < y[i]) cnt[x[i]][2] ++, res += (y[i] - 2), y[i] = 2;
}
if (x[i] < 1) {
res += 1 - x[i];
if (1 <= y[i] && y[i] <= 2) cnt[1][y[i]] ++;
if (y[i] < 1) cnt[1][1] ++, res += (1 - y[i]), y[i] = 1;
if (2 < y[i]) cnt[1][2] ++, res += (y[i] - 2), y[i] = 2;
x[i] = 1;
}
if (n < x[i]) {
res += x[i] - n;
if (1 <= y[i] && y[i] <= 2) cnt[n][y[i]] ++;
if (y[i] < 1) cnt[n][1] ++, res += (1 - y[i]), y[i] = 1;
if (2 < y[i]) cnt[n][2] ++, res += (y[i] - 2), y[i] = 2;
x[i] = n;
}
}
int a = 0, b = 0;
for (int i = 1; i <= n; ++ i) {
a += (cnt[i][1] - 1), b += (cnt[i][2] - 1);
if ((a > 0 && b < 0) || (a < 0 && b > 0)) {
int mn = min (abs(a), abs(b));
res += mn;
if (b < 0) b += mn;
else b -= mn;
if (a < 0) a += mn;
else a -= mn;
}
res += abs(a) + abs(b);
}
cout << res;
return;
}
signed main() {
// YOSIK();
// srand (time(0));
// freopen ("E.in", "r", stdin);
// freopen ("E.out", "w", stdout);
int TT = 1;// cin >> TT;
for (int i = 1; i <= TT; ++ i) {
// cout << "Case " << i << ": ";
solution ();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6592 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6592 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6588 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6592 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6592 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6588 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
2 ms |
6492 KB |
Output is correct |
36 |
Correct |
2 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
2 ms |
6492 KB |
Output is correct |
41 |
Correct |
3 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6488 KB |
Output is correct |
44 |
Correct |
2 ms |
6624 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
2 ms |
6616 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6492 KB |
Output is correct |
52 |
Correct |
2 ms |
6504 KB |
Output is correct |
53 |
Correct |
2 ms |
6492 KB |
Output is correct |
54 |
Correct |
2 ms |
6492 KB |
Output is correct |
55 |
Correct |
2 ms |
6492 KB |
Output is correct |
56 |
Correct |
2 ms |
6492 KB |
Output is correct |
57 |
Correct |
3 ms |
6488 KB |
Output is correct |
58 |
Correct |
2 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6492 KB |
Output is correct |
61 |
Correct |
2 ms |
6488 KB |
Output is correct |
62 |
Correct |
2 ms |
6492 KB |
Output is correct |
63 |
Correct |
2 ms |
6492 KB |
Output is correct |
64 |
Correct |
2 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6592 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6592 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6588 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
2 ms |
6492 KB |
Output is correct |
36 |
Correct |
2 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
2 ms |
6492 KB |
Output is correct |
41 |
Correct |
3 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6488 KB |
Output is correct |
44 |
Correct |
2 ms |
6624 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
2 ms |
6616 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6492 KB |
Output is correct |
52 |
Correct |
2 ms |
6504 KB |
Output is correct |
53 |
Correct |
2 ms |
6492 KB |
Output is correct |
54 |
Correct |
2 ms |
6492 KB |
Output is correct |
55 |
Correct |
2 ms |
6492 KB |
Output is correct |
56 |
Correct |
2 ms |
6492 KB |
Output is correct |
57 |
Correct |
3 ms |
6488 KB |
Output is correct |
58 |
Correct |
2 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6492 KB |
Output is correct |
61 |
Correct |
2 ms |
6488 KB |
Output is correct |
62 |
Correct |
2 ms |
6492 KB |
Output is correct |
63 |
Correct |
2 ms |
6492 KB |
Output is correct |
64 |
Correct |
2 ms |
6488 KB |
Output is correct |
65 |
Correct |
60 ms |
12112 KB |
Output is correct |
66 |
Correct |
126 ms |
13344 KB |
Output is correct |
67 |
Correct |
95 ms |
13716 KB |
Output is correct |
68 |
Correct |
96 ms |
13720 KB |
Output is correct |
69 |
Correct |
102 ms |
13724 KB |
Output is correct |
70 |
Correct |
96 ms |
13720 KB |
Output is correct |
71 |
Correct |
105 ms |
13720 KB |
Output is correct |
72 |
Correct |
96 ms |
11860 KB |
Output is correct |
73 |
Correct |
101 ms |
11856 KB |
Output is correct |
74 |
Correct |
96 ms |
11936 KB |
Output is correct |
75 |
Correct |
111 ms |
11668 KB |
Output is correct |
76 |
Correct |
100 ms |
11812 KB |
Output is correct |
77 |
Correct |
112 ms |
13908 KB |
Output is correct |
78 |
Correct |
96 ms |
13904 KB |
Output is correct |
79 |
Correct |
98 ms |
13908 KB |
Output is correct |
80 |
Correct |
96 ms |
13912 KB |
Output is correct |
81 |
Correct |
138 ms |
12056 KB |
Output is correct |
82 |
Correct |
97 ms |
13852 KB |
Output is correct |
83 |
Correct |
96 ms |
13848 KB |
Output is correct |
84 |
Correct |
104 ms |
13908 KB |
Output is correct |
85 |
Correct |
96 ms |
13908 KB |
Output is correct |
86 |
Correct |
106 ms |
13852 KB |
Output is correct |
87 |
Correct |
96 ms |
13848 KB |
Output is correct |
88 |
Correct |
111 ms |
13724 KB |
Output is correct |
89 |
Correct |
97 ms |
13856 KB |
Output is correct |
90 |
Correct |
102 ms |
13720 KB |
Output is correct |
91 |
Correct |
96 ms |
13720 KB |
Output is correct |
92 |
Correct |
98 ms |
13848 KB |
Output is correct |
93 |
Correct |
98 ms |
14016 KB |
Output is correct |
94 |
Correct |
92 ms |
13648 KB |
Output is correct |
95 |
Correct |
92 ms |
13648 KB |
Output is correct |
96 |
Correct |
97 ms |
13908 KB |
Output is correct |
97 |
Correct |
97 ms |
13848 KB |
Output is correct |
98 |
Correct |
96 ms |
11860 KB |
Output is correct |
99 |
Correct |
105 ms |
13904 KB |
Output is correct |
100 |
Correct |
98 ms |
13864 KB |
Output is correct |
101 |
Correct |
96 ms |
13908 KB |
Output is correct |
102 |
Correct |
96 ms |
11856 KB |
Output is correct |
103 |
Correct |
101 ms |
12116 KB |
Output is correct |