이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 100'010;
int a[2][N];
int n;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
memset(a, -1, sizeof(a));
ll ans = 0;
cin >> n;
Loop (i,0,2*n) {
int x, y;
cin >> x >> y;
if (x < 1) {
ans += 1-x;
x = 1;
}
if (x > n) {
ans += x-n;
x = n;
}
if (y < 1) {
ans += 1-y;
y = 1;
}
if (y > 2) {
ans += y-2;
y = 2;
}
a[y-1][x-1]++;
}
Loop (i,0,n) {
if ((a[0][i] < 0) != (a[1][i] < 0)) {
int mv = min(abs(a[0][i]), abs(a[1][i]));
ans += mv;
a[0][i] += a[0][i] < 0? mv: -mv;
a[1][i] += a[1][i] < 0? mv: -mv;
}
ans += abs(a[0][i]) + abs(a[1][i]);
a[0][i+1] += a[0][i];
a[1][i+1] += a[1][i];
}
cout << ans << '\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... |