# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203096 | ics0503 | Coin Collecting (JOI19_ho_t4) | C++17 | 5 ms | 256 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
#include<deque>
using namespace std;
struct xy { int x, y; }a[212121];
bool sort_x(xy a, xy b) {
if (a.x != b.x)return a.x < b.x;
return a.y < b.y;
}
deque<xy>L[2];
int jd(int x) { if (x > 0)return x; return -x; }
int calc(int x, int y, int a, int b) {
printf("%d %d -> %d %d\n", x, y, a, b);
return jd(x - a) + jd(y - b);
}
int main() {
int n, i, j; scanf("%d", &n);
for (i = 0; i < n * 2; i++) scanf("%d%d", &a[i].x, &a[i].y);
sort(a, a + n * 2, sort_x);
int p = 0, idx[2] = { 0, 0 };
long long ans = 0;
for (i = 1; i <= n + 1; i++) {
while (p < 2 * n && (i == n + 1 || a[p].x <= i)) L[a[p].y > 1].push_back(a[p++]);
for (j = 0; j < 2; j++) {
while (idx[j]<n && idx[j] < i && !L[j].empty()) {
xy f = L[j].front(); L[j].pop_front(); idx[j]++;
ans += calc(f.x, f.y, idx[j], j + 1);
}
}
for (j = 0; j < 2; j++) {
while (idx[j]<n && idx[j] < i && !L[!j].empty()) {
xy f = L[!j].front(); L[!j].pop_front(); idx[j]++;
ans += calc(f.x, f.y, idx[j], j + 1);
}
}
}
printf("%lld", ans);
return 0;
}
Compilation message (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... |