이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int nax = 1e5;
int n, cnt[nax + 1][2], bil[2]; ll res;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= 2 * n; ++i)
{
int x, y; cin >> x >> y;
res += max(0, x - n);
res += max(0, 1 - x);
res += max(0, y - 2);
res += max(0, 1 - y);
x = min(x, n);
x = max(x, 1);
y = min(y, 2);
y = max(y, 1);
++cnt[x][y - 1];
}
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j < 2; ++j)
bil[j] += cnt[i][j], --bil[j];
for (int j = 0; j < 2; ++j)
if (bil[j] > 0 and bil[1 - j] < 0)
{
int q = min(-bil[1 - j], bil[j]);
res += q;
bil[j] -= q;
bil[1 - j] += q;
}
for (int j = 0; j < 2; ++j)
res += abs(bil[j]);
}
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... |