Submission #878778

#TimeUsernameProblemLanguageResultExecution timeMemory
878778frostray8653Coin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h> #define int long long #define IO ios::sync_with_stdio(0), cin.tie(0) #define FOR(i, a, b) for (int i = a, I = b; i <= I; i++) using namespace std; using pii = pair<int, int>; void dbg() {;} template<class T, class ...U> void dbg(T a, U ...b) { cout << a << " "; dbg(b...); } void ent() { cout << "\n"; } const int N = 200005; pii a[N]; int mp[N][2]; signed main() { IO; int n; cin >> n; FOR(i, 1, 2 * n) cin >> a[i].first >> a[i].second; int ans = 0; FOR(i, 1, 2 * n) { auto [x, y] = a[i]; int tarx, tary; if (x <= 1) tarx = 1; else if (x >= n) tarx = n; else tarx = x; if (y <= 1) tary = 1; else tary = 2; ans += abs(tarx - x) + abs(tary - y); mp[tarx][tary] += 1; } int U_cnt = 0; int D_cnt = 0; FOR(i, 1, n) { if (mp[i][1] == 0) { if (mp[i][2] > 1) { mp[i][2] -= 1; mp[i][1] += 1; ans += 1; } else { D_cnt += 1; } } if (mp[i][2] == 0) { if (mp[i][1] > 1) { mp[i][1] -= 1; mp[i][2] += 1; ans += 1; } else { U_cnt += 1; } } if (mp[i][1] > 1) { if (D_cnt > 0) { int dif = min(mp[i][1] - 1, D_cnt); D_cnt -= dif; mp[i][1] -= dif; } } if (mp[i][2] > 1) { if (U_cnt > 0) { int dif = min(mp[i][2] - 1, U_cnt); U_cnt -= dif; mp[i][2] -= dif; } } if (mp[i][1] > 1) { if (U_cnt > 0) { int dif = min(mp[i][1] - 1, U_cnt); U_cnt -= dif; mp[i][1] -= dif; ans += dif; } } if (mp[i][2] > 1) { if (D_cnt > 0) { int dif = min(mp[i][2] - 1, D_cnt); D_cnt -= dif; mp[i][2] -= dif; ans += dif; } } if (mp[i][1] > 1) { ans += mp[i][1] - 1; mp[i + 1][1] += mp[i][1] - 1; mp[i][1] = 1; } if (mp[i][2] > 1) { ans += mp[i][2] - 1; mp[i + 1][2] += mp[i][2] - 1; mp[i][2] = 1; } ans += U_cnt + D_cnt; } cout << ans << "\n"; return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:43:24: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   43 |             if (mp[i][2] > 1) {
      |                 ~~~~~~~^
joi2019_ho_t4.cpp:44:26: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   44 |                 mp[i][2] -= 1;
      |                 ~~~~~~~~~^~~~
joi2019_ho_t4.cpp:51:20: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   51 |         if (mp[i][2] == 0) {
      |             ~~~~~~~^
joi2019_ho_t4.cpp:54:26: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   54 |                 mp[i][2] += 1;
      |                 ~~~~~~~~~^~~~
joi2019_ho_t4.cpp:67:20: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   67 |         if (mp[i][2] > 1) {
      |             ~~~~~~~^
joi2019_ho_t4.cpp:71:26: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   71 |                 mp[i][2] -= dif;
      |                 ~~~~~~~~~^~~~~~
joi2019_ho_t4.cpp:82:20: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   82 |         if (mp[i][2] > 1) {
      |             ~~~~~~~^
joi2019_ho_t4.cpp:86:26: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   86 |                 mp[i][2] -= dif;
      |                 ~~~~~~~~~^~~~~~
joi2019_ho_t4.cpp:95:20: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   95 |         if (mp[i][2] > 1) {
      |             ~~~~~~~^
joi2019_ho_t4.cpp:97:26: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   97 |             mp[i + 1][2] += mp[i][2] - 1;
      |             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:97:26: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
joi2019_ho_t4.cpp:98:20: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   98 |             mp[i][2] = 1;
      |             ~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...