이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N = 1e5 + 9;
int n, cnt[4][N];
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n;
ll sum(0);
for (int i = 1, x, y; i <= n * 2; ++i) {
cin >> x >> y;
if (x < 1) sum += 1 - x, x = 1;
if (n < x) sum += x - n, x = n;
if (y < 1) sum += 1 - y, y = 1;
if (2 < y) sum += y - 2, y = 2;
++cnt[y][x];
}
for (int i = 1; i <= n; ++i) {
--cnt[1][i], --cnt[2][i];
if (cnt[1][i] > 0 && cnt[2][i] < 0) {
int mi = min(cnt[1][i], -cnt[2][i]);
cnt[1][i] -= mi;
cnt[2][i] += mi;
sum += mi;
}
else if (cnt[1][i] < 0 && cnt[2][i] > 0) {
int mi = min(-cnt[1][i], cnt[2][i]);
cnt[1][i] += mi;
cnt[2][i] -= mi;
sum += mi;
}
cnt[1][i + 1] += cnt[1][i];
sum += abs(cnt[1][i]);
cnt[2][i + 1] += cnt[2][i];
sum += abs(cnt[2][i]);
}
cout << sum << '\n';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |