Submission #225228

#TimeUsernameProblemLanguageResultExecution timeMemory
225228MKopchevCoin Collecting (JOI19_ho_t4)C++14
100 / 100
95 ms4984 KiB
#include<bits/stdc++.h> using namespace std; const int nmax=2e5+42; int seen[nmax][3]; int active[3]; int main() { long long output=0; int n,x,y; scanf("%i",&n); for(int i=1;i<=2*n;i++) { scanf("%i%i",&x,&y); if(x>n){output+=x-n;x=n;} if(x<1){output+=1-x;x=1;} if(y>2){output+=y-2;y=2;} if(y<1){output+=1-y;y=1;} seen[x][y]++; } for(int i=1;i<=n;i++) { active[1]+=seen[i][1]-1; active[2]+=seen[i][2]-1; if(active[1]>0&&active[2]<0) { int add=min(active[1],-active[2]); active[1]-=add; active[2]+=add; output+=add; } if(active[1]<0&&active[2]>0) { int add=min(-active[1],active[2]); active[1]+=add; active[2]-=add; output+=add; } output+=abs(active[1])+abs(active[2]); } printf("%lld\n",output); return 0; }

Compilation message (stderr)

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