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