#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n;
vector <vector <int> > a;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(2, vector <int>(n, 0));
ll ans = 0;
for(int i = 0 ; i < 2 * n ; i++){
int x, y;
cin >> x >> y;
int nx = min(n, max(1, x));
int ny = min(2, max(1, y));
ans += abs(nx - x) + abs(ny - y);
a[ny - 1][nx - 1]++;
}
vector <vector <int> > sum(2, vector <int>(n, 0));
for(int i = 0 ; i < 2 ; i++){
for(int j = n - 1 ; j >= 0 ; j--){
if(j < n - 1) sum[i][j] = sum[i][j + 1];
sum[i][j] += a[i][j];
}
}
for(int itt = 0 ; itt < 2 ; itt++){
int cur = a[0][0] + a[1][0];
for(int j = 1 ; j < n ; j++){
int g = max(cur - 2 * j, 0);
cur += a[0][j] + a[1][j];
int s0 = sum[0][j], s1 = sum[1][j];
while(g--){
int f = 0;
if(s0 < s1){
if(a[0][j - 1] > 1) f = 0;
else f = 1;
}
else{
if(a[1][j - 1] > 1) f = 1;
else f = 0;
}
a[f][j - 1]--;
a[f][j]++;
ans++;
}
}
for(int i = 0 ; i < 2 ; i++){
reverse(a[i].begin(), a[i].end());
}
}
for(int j = 0 ; j < n ; j++){
if(a[0][j] != 1) ans++;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |