#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN=1e5+5;
int n;
int cnt[2][MAXN];
long long ans=0;
void add(int t,int x)
{
if(x<1)
{
ans+=1-x;
cnt[t][1]++;
}
else if(x>n)
{
ans+=x-n;
cnt[t][n]++;
}
else cnt[t][x]++;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(int i=1; i<=2*n; i++)
{
int x,y;
cin>>x>>y;
if(y<=1)
{
add(0,x);
ans+=1-y;
}
else
{
add(1,x);
ans+=y-2;
}
}
int r0=0,r1=0;
for(int i=1; i<=n; i++)
{
r0+=cnt[0][i];
r1+=cnt[1][i];
/*int vert=0;
if(r0<i && i<r1)
{
vert=min(i-r0, r1-i);
r0+=vert;
r1-=vert;
}
if(r0>i && i>r1)
{
vert=min(r0-i, i-r1);
r0-=vert;
r1+=vert;
}
ans+=vert;*/
ans+=abs(r0+r1-2*i);
}
ans+=abs(r0-n);
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |