Submission #232201

#TimeUsernameProblemLanguageResultExecution timeMemory
232201jamielimCoin Collecting (JOI19_ho_t4)C++14
100 / 100
86 ms6524 KiB
#include <bits/stdc++.h> using namespace std; int main(){ long long n; scanf("%lld",&n); long long x,y; long long ans=0; int c[2][n]; memset(c,0,sizeof(c)); for(int i=0;i<2*n;i++){ scanf("%lld%lld",&x,&y); if(x<1)ans+=(1LL-x),x=1; if(x>n)ans+=(x-n),x=n; if(y<1)ans+=(1LL-y),y=1; if(y>2)ans+=(y-2LL),y=2; c[y-1][x-1]++; } int ptr[2]; ptr[0]=ptr[1]=0; queue<int> q[2]; for(int i=0;i<n;i++){ for(int j=0;j<c[0][i];j++)q[0].push(i); for(int j=0;j<c[1][i];j++)q[1].push(i); while(!q[0].empty()&&ptr[0]<=i){ans+=(long long)(abs(q[0].front()-ptr[0]));q[0].pop(),ptr[0]++;} while(!q[1].empty()&&ptr[1]<=i){ans+=(long long)(abs(q[1].front()-ptr[1]));q[1].pop(),ptr[1]++;} while(!q[0].empty()&&ptr[1]<=i){ans+=(long long)(abs(q[0].front()-ptr[1])+1);q[0].pop(),ptr[1]++;} while(!q[1].empty()&&ptr[0]<=i){ans+=(long long)(abs(q[1].front()-ptr[0])+1);q[1].pop(),ptr[0]++;} } printf("%lld",ans); }

Compilation message (stderr)

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