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