Submission #730434

#TimeUsernameProblemLanguageResultExecution timeMemory
730434speedyArdaCoin Collecting (JOI19_ho_t4)C++14
100 / 100
193 ms7320 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const int MAXN = 1e5+5; ll cnt[MAXN][3]; int main() { int n; cin >> n; ll ans = 0; for(int i = 1; i <= 2 * n; i++) { int x, y; cin >> x >> y; if(x <= 1) { ans += 1 - x; x = 1; } else if(x > n) { ans += x - n; x = n; } if(y <= 1) { ans += 1 - y; y = 1; } else { ans += y - 2; y = 2; } cnt[x][y]++; } ll up = 1, down = 1; ll remup = 0, remdown = 0; for(int pr=1; pr<=n ;pr++){ while(up<=pr && cnt[pr][1]>0) ans+=pr-up++,cnt[pr][1]--; while(down<=pr && cnt[pr][2]>0) ans+=pr-down++,cnt[pr][2]--; while(up>pr && down<=pr && cnt[pr][1]>0) ans+=pr+1-down++,cnt[pr][1]--; while(down>pr && up<=pr && cnt[pr][2]>0) ans+=pr+1-up++,cnt[pr][2]--; ans+=cnt[pr][1];cnt[pr+1][1]+=cnt[pr][1];cnt[pr][1]=0; ans+=cnt[pr][2];cnt[pr+1][2]+=cnt[pr][2];cnt[pr][2]=0; } cout << ans << "\n"; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:35:8: warning: unused variable 'remup' [-Wunused-variable]
   35 |     ll remup = 0, remdown = 0;
      |        ^~~~~
joi2019_ho_t4.cpp:35:19: warning: unused variable 'remdown' [-Wunused-variable]
   35 |     ll remup = 0, remdown = 0;
      |                   ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...