Submission #226338

#TimeUsernameProblemLanguageResultExecution timeMemory
226338Ruxandra985Coin Collecting (JOI19_ho_t4)C++14
100 / 100
83 ms9212 KiB
#include <bits/stdc++.h> using namespace std; pair <long long,long long> v[200010]; long long f[200010][3]; long long modul (long long x){ return max(x , -x); } int main() { FILE *fin = stdin; FILE *fout = stdout; long long i , n , j , under1 , under2 , cnt1 , cnt2 , ic , jc; long long sol = 0; fscanf (fin,"%lld",&n); for (i = 1 ; i <= 2 * n ; i++){ fscanf (fin,"%lld%lld",&v[i].first,&v[i].second); /// acum reduci v ul if (v[i].second <= 1){ sol = sol + 1 - v[i].second; v[i].second = 1; } else { sol = sol + v[i].second - 2; v[i].second = 2; } if (v[i].first < 1){ sol = sol + 1 - v[i].first; v[i].first = 1; } else if (v[i].first > n){ sol = sol + v[i].first - n; v[i].first = n; } f[v[i].first][v[i].second]++; } /// renunt la heap gata ok am inteles, nu e bn:))))) /// ok o sa renunt si la celalalt greedy :((( ic = 1; jc = 1; for (i = 1 ; i <= n ; i++){ for (j = 1 ; j <= f[i][1] + f[i][2] ; j++){ sol = sol + modul(i - ic); jc++; if (jc == 3){ jc = 1; ic++; } } } under1 = under2 = 0; cnt1 = cnt2 = 0; for (i = 1 ; i <= n ; i++){ under1++; under2++; cnt1 += f[i][1]; cnt2 += f[i][2]; while (under1 && cnt1){ under1--; cnt1--; } while (under2 && cnt2){ under2--; cnt2--; } while (under1 && cnt2){ under1--; cnt2--; sol++; } while (under2 && cnt1){ under2--; cnt1--; sol++; } } fprintf (fout,"%lld",sol); return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:17:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%lld",&n);
     ~~~~~~~^~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:19:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lld%lld",&v[i].first,&v[i].second);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...