Submission #1034577

#TimeUsernameProblemLanguageResultExecution timeMemory
1034577juicyCoin Collecting (JOI19_ho_t4)C++17
100 / 100
37 ms4944 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 1e5 + 5; int n; int cnt[N][2]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; long long res = 0; for (int i = 0; i < 2 * n; ++i) { int x, y; cin >> x >> y; if (x > n) { res += x - n; x = n; } else if (x < 1) { res += 1 - x; x = 1; } if (y < 2) { res += 1 - y; y = 1; } else { res += y - 2; y = 2; } assert(1 <= x && x <= n && 1 <= y && y <= 2); ++cnt[x][y]; } int a = 0, b = 0; for (int i = 1; i <= n; ++i) { a += cnt[i][1] - 1, b += cnt[i][2] - 1; while (a > 0 && b < 0) { a--, b++, res++; } while (a < 0 && b > 0) { a++, b--, res++; } res += abs(a) + abs(b); } cout << res; return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:42:38: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   42 |     a += cnt[i][1] - 1, b += cnt[i][2] - 1;
      |                              ~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...