# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1116199 | Dan4Life | Coin Collecting (JOI19_ho_t4) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
#define int long long
int n, a[100010][2], b[2];
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n; int ans = 0;
for(int i = 0; i < 2*n; i++){
int x,y,X,Y; cin >> x >> y; X=x,Y=y;
x=clamp(x,1ll,n), y=clamp(y,1ll,2ll);
ans+=abs(X-x)+abs(Y-y); a[x][y-1]++;
}
for(int i = 1; i <= n; i++){
b[0]+=a[i][0]-1,b[1]+=a[i][1]-1;
for(int j : {0,1}){
int xd=min(abs(b[0]),abs(b[1]));
if(b[j]>0 and b[j^1]<0)
ans+=xd,b[j]-=xd,b[j^1]+=xd;
}
ans+=abs(b[0])+abs(b[1]);
}
cout << ans << "\n";
}