This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;
int n, X[N], Y[N], cnt[N][2];
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
ll ans = 0;
for (int i = 1; i <= 2 * n; i++){
cin >> X[i] >> Y[i];
int x, y;
if (abs(Y[i] - 1) < abs(Y[i] - 2)){
y = 1;
ans += abs(Y[i] - 1);
}else y = 2, ans += abs(Y[i] - 2);
if (1 <= X[i] && X[i] <= n) x = X[i];
else if(X[i] < 1) x = 1;
else x = n;
ans += abs(X[i] - x);
// cout << X[i] << ' ' << Y[i] << ' ' << x << ' ' << y << '\n';
cnt[x][y - 1] ++;
}
// cout << ans << '\n';
ll sm1 = 0, sm2 = 0;
// for (int i = 1; i <= n; i++) cout << cnt[i][0] << ' ' << cnt[i][1] << '\n';
for (int i = 1; i <= n; i++) sm1 += cnt[i][0], sm2 += cnt[i][1];
ans += abs(sm1 - sm2) / 2;
ll sm = 0;
for (int i = 1; i <= n; i++){
sm += cnt[i][0] + cnt[i][1];
sm2 = 2 * n - sm;
ans += max(0ll, 2 * i - sm);
ans += max(0ll, 2 * (n - i) - sm2);
}
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... |