#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
#define pb push_back
#define st first
#define nd second
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
int ile[n][2];
rep(i, n) {
rep(c, 2) {
ile[i][c] = 0;
}
}
ll ans = 0;
rep(i, 2 * n) {
ll x, y;
cin >> x >> y;
if (x >= 1 && x <= n) {
if (y >= 2) {
ile[x - 1][1]++;
ans += (y - 2);
}
else {
ile[x - 1][0]++;
ans += (1 - y);
}
}
else if (x < 1) {
if (y >= 2) {
ile[0][1]++;
ans += (y - 2) + (1 - x);
}
else {
ile[0][0]++;
ans += (1 - y) + (1 - x);
}
}
else {
if (y >= 2) {
ile[n - 1][1]++;
ans += (y - 2) + (x - n);
}
else {
ile[n - 1][0]++;
ans += (1 - y) + (x - n);
}
}
}
ll a, b;
ll x, y;
x = 0;
y = 0;
a = 0;
b = 0;
rep(i, n) {
x += ile[i][0];
y += ile[i][1];
ll p = i + 1;
while (x > 0 && a < p) {
ans += (p - 1 - a);
a++;
x--;
}
while (y > 0 && b < p) {
ans += (p - 1 - b);
b++;
y--;
}
while (x > 0 && b < p) {
ans += (p - b);
b++;
x--;
}
while (y > 0 && a < p) {
ans += (p - a);
a++;
y--;
}
ans += x;
ans += y;
}
cout << ans << '\n';
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... |