Submission #203096

#TimeUsernameProblemLanguageResultExecution timeMemory
203096ics0503Coin Collecting (JOI19_ho_t4)C++17
0 / 100
5 ms256 KiB
#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)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:23:79: warning: operation on 'p' may be undefined [-Wsequence-point]
   while (p < 2 * n && (i == n + 1 || a[p].x <= i)) L[a[p].y > 1].push_back(a[p++]);
                                                                              ~^~
joi2019_ho_t4.cpp:17:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, i, j; scanf("%d", &n);
               ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:18:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 0; i < n * 2; i++) scanf("%d%d", &a[i].x, &a[i].y);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...