# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
121222 | ainta | Coin Collecting (JOI19_ho_t4) | C++17 | 64 ms | 5496 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<algorithm>
using namespace std;
int n, C[101000][2];
long long res;
struct point {
int x, y;
}w[101000];
void Make(int &x, int b, int e) {
if (x < b)res += b - x, x = b;
if (x > e)res += x - e, x = e;
}
void Do(int pv) {
if (pv == n + 1)return;
int t1 = C[pv][0] - 1;
int t2 = C[pv][1] - 1;
if(1ll*t1*t2<0){
int t = min(abs(t1), abs(t2));
if (t1 < 0)t1 += t; else t1 -= t;
if (t2 < 0)t2 += t; else t2 -= t;
res += t;
}
res += abs(t1) + abs(t2);
C[pv + 1][0] += t1, C[pv + 1][1] += t2;
Do(pv + 1);
}
int main() {
int i, x, y;
scanf("%d", &n);
for (i = 1; i <= 2*n; i++) {
scanf("%d%d", &x, &y);
Make(x, 1, n);
Make(y, 1, 2);
C[x][y - 1]++;
}
Do(1);
printf("%lld\n", res);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |