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