//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")
#define int long long
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 |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |