#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;
using pp=pair<int, int>;
#define rep(i, n) for (int i=0; i<n; ++i)
#define rrep(i, n) for (int i=1; i<=n; ++i)
const int maxn = int(1e5) + 10;
int n;
ll ans;
int c[3][maxn];
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
rrep(i, 2*n) {
int x, y; cin >> x >> y;
auto Bound = [&](int &v, int l, int r) {
if (v < l) { ans += l-v; v = l; }
else if (v > r) { ans += v-r; v = r; }
};
Bound(x, 1, n);
Bound(y, 1, 2);
++c[y][x];
}
for (int i=1, cl=0; i<n; ++i) {
rrep(j, 2) cl+=c[j][i];
int need = i*2;
ans += abs(need-cl);
}
int uc = 0;
for (int i=1; i<=n; ++i) uc += c[1][i];
ans += abs(n-uc);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |