#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("i.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
long long ans = 0ll;
int n;
cin >> n;
int arr[n][2];
for(int i = 0;i < n;i++){
arr[i][0] = 0;
arr[i][1] = 0;
}
for(int i = 0;i < 2 * n;i++){
long long x, y;
cin >> x >> y;
if(x <= 1){
if(y <= 1){
arr[0][0]++;
ans += abs(y-1) + abs(x-1);
}
else{
arr[0][1]++;
ans += abs(y-2) + abs(x-1);
}
}
else if(x >= n){
if(y <= 1){
arr[n-1][0]++;
ans += abs(y-1) + abs(x-n);
}
else{
arr[n-1][1]++;
ans += abs(y-2) + abs(x-n);
}
}
else{
if(y <= 1){
arr[x-1][0]++;
ans += abs(y-1);
}
else{
arr[x-1][1]++;
ans += abs(y-2);
}
}
}
int comb[n];
int col = 0;
for(int i = 0;i < n;i++){
comb[i] = arr[i][0] + arr[i][1];
col += arr[i][0];
col -= arr[i][1];
}
for(int i = 0;i < n;i++){
int x = comb[i] - 2;
ans += abs(x);
comb[i] = 2;
if(i != n-1) comb[i+1] += x;
}
col /= 2;
ans += abs(col);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |