#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<>,
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
#define ll long long
#define ii pair<ll,ll>
#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif
const ll inf=1e15;
const ll maxn=1e5+5;
const ll mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll arr[maxn][3];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,x,y,ans=0;
cin>>n;
for (int i=1;i<=2*n;i++){
cin>>x>>y;
if (x<=1 && y<=1) arr[1][1]++, ans+=abs(1-x)+abs(1-y);
else if (1<x && x<n && y<=1) arr[x][1]++, ans+=abs(1-y);
else if (x>=n && y<=1) arr[n][1]++, ans+=abs(n-x)+abs(1-y);
else if (x<=1 && y>=2) arr[1][2]++, ans+=abs(1-x)+abs(2-y);
else if (1<x && x<n && y>=2) arr[x][2]++, ans+=abs(2-y);
else arr[n][2]++, ans+=abs(n-x)+abs(2-y);
}
ll tot=0;
for (int i=1;i<=2;i++){
for (int j=1;j<=n;j++) cerr<<arr[j][i]<<' ';
cerr<<endl;
}
for (int i=1;i<=n;i++){
tot+=arr[i][1]+arr[i][2];
ans+=abs(tot-2*i);
}
assert(tot==2*n);
tot=0;
for (int i=1;i<=n;i++){
tot+=arr[i][1];
}
ans+=abs(n-tot);
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |