이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long a[100005][3], b[3];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, ans=0;
cin >> n;
for (long long i=1; i<=n*2; i++)
{
long long x, y;
cin >> x >> y;
if (x<1)
ans+=1-x, x=1;
if (x>n)
ans+=x-n, x=n;
if (y<1)
ans+=1-y, y=1;
if (y>2)
ans+=y-2, y=2;
a[x][y]++;
}
for (long long i=1; i<=n; i++)
{
b[1]+=a[i][1]-1;
b[2]+=a[i][2]-1;
if (b[1]>0 && b[2]<0)
{
long long mn=min(b[1], -b[2]);
ans+=mn, b[1]-=mn, b[2]+=mn;
}
else if (b[1]<0 && b[2]>0)
{
long long mn=min(-b[1], b[2]);
ans+=mn, b[1]+=mn, b[2]-=mn;
}
ans+=abs(b[1])+abs(b[2]);
}
cout << ans;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |