Submission #430245

#TimeUsernameProblemLanguageResultExecution timeMemory
430245PyqeCoin Collecting (JOI19_ho_t4)C++14
100 / 100
89 ms2616 KiB
#include <bits/stdc++.h> using namespace std; long long n,ps[2][100069],ca[6]; int main() { long long i,ii,jj,u,x,y,x2,y2,lb,rb,z=0; scanf("%lld",&n); for(i=1;i<=n*2;i++) { scanf("%lld%lld",&x,&y); x2=min(max(x,1ll),n); y2=min(max(y,1ll),2ll); z+=abs(x-x2)+abs(y-y2); ps[y2-1][x2]++; } for(ii=0;ii<2;ii++) { u=!ii*2-1; for(i=1;i<=n;i++) { ps[ii][i]=ps[ii][i-1]+(ps[ii][i]-1)*u; } } lb=0; rb=0; for(i=1;i<n;i++) { if(ps[0][i]>ps[1][i]) { swap(ps[0][i],ps[1][i]); } z+=ps[1][i]-ps[0][i]; z+=max(ps[0][i]-rb,0ll)+max(lb-ps[1][i],0ll); ca[0]=lb; ca[1]=rb; for(ii=0;ii<2;ii++) { for(jj=0;jj<2;jj++) { ca[2+ii*2+jj]=ps[jj][i]; } } sort(ca,ca+6); lb=ca[2]; rb=ca[3]; } z+=max(ps[0][n]-rb,0ll)+max(lb-ps[1][n],0ll); printf("%lld\n",z); }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%lld%lld",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...