Submission #430259

#TimeUsernameProblemLanguageResultExecution timeMemory
430259Nicholas_PatrickCoin Collecting (JOI19_ho_t4)C++17
100 / 100
63 ms1092 KiB
#include <cstdio> #include <queue> #include <algorithm> using namespace std; int diff(int x, int y){ return x<y?y-x:x-y; } int ab(int x){ return x<0?-x:x; } struct point{ int x, y; }; int main(){ int n; scanf("%d", &n); vector<int> top(n, -1), bot(n, -1); long long ans=0; for(int i=n*2; i--;){ int x, y; scanf("%d%d", &x, &y); if(y>2){ ans+=y-2; y=2; } if(y<1){ ans+=1-y; y=1; } if(x<1){ ans+=1-x; x=1; } if(x>n){ ans+=x-n; x=n; } if(y==2) top[x-1]++; else bot[x-1]++; } for(int i=0; i<n; i++){ if(top[i]>=0){ if(bot[i]<0){ if(top[i]<-bot[i]){ ans+=top[i]; bot[i]+=top[i]; top[i]-=top[i]; }else{ ans-=bot[i]; top[i]+=bot[i]; bot[i]-=bot[i]; } } }else{ if(bot[i]>=0){ if(-top[i]<bot[i]){ ans-=top[i]; bot[i]+=top[i]; top[i]-=top[i]; }else{ ans+=bot[i]; top[i]+=bot[i]; bot[i]-=bot[i]; } } } if(top[i]){ ans+=ab(top[i]); top[i+1]+=top[i]; } if(bot[i]){ ans+=ab(bot[i]); bot[i+1]+=bot[i]; } } printf("%lld\n", ans); }

Compilation message (stderr)

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