이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
long long ans = 0;
vector<vector<int>> need(3, vector<int>(N + 1));
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= N; j++) {
need[i][j] = -1;
}
}
for (int i = 0; i < 2 * N; i++) {
int x, y;
cin >> x >> y;
if (x < 1) ans += 1 - x;
if (x > N) ans += x - N;
x = clamp(x, 1, N);
if (y < 1) ans += 1 - y;
if (y > 2) ans += y - 2;
y = clamp(y, 1, 2);
need[y][x] += 1;
}
vector<int> flow(3);
for (int p = 1; p <= N; p++) {
flow[1] += need[1][p];
flow[2] += need[2][p];
if (flow[1] < 0 && flow[2] > 0) {
swap(flow[1], flow[2]);
swap(need[1], need[2]);
}
if (flow[1] > 0 && flow[2] < 0) {
int f = min(abs(flow[1]), abs(flow[2]));
flow[1] -= f;
flow[2] += f;
ans += f;
}
ans += abs(flow[1]);
ans += abs(flow[2]);
}
assert(flow[1] == 0 && flow[2] == 0);
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... |