Submission #126597

#TimeUsernameProblemLanguageResultExecution timeMemory
126597HungAnhGoldIBO2020Coin Collecting (JOI19_ho_t4)C++14
100 / 100
350 ms5240 KiB
#include<iostream> #include<math.h> using namespace std; const int N=1e5+2; int cnt[N][4]; int main(){ int n,i,j,k,l; long long ans=0; cin>>n; for(i=1;i<=2*n;i++){ cin>>j>>k; if(j>n){ ans+=j-n; j=n; } if(j<1){ ans+=1-j; j=1; } if(k>2){ ans+=k-2; k=2; } if(k<1){ ans+=1-k; k=1; } cnt[j][k]++; } j=0; k=0; //cout<<ans<<endl; for(i=1;i<=n;i++){ // cout<<j<<" "<<k<<" "<<cnt[i][1]<<" "<<cnt[i][2]<<" "<<ans<<endl; j+=cnt[i][1]; k+=cnt[i][2]; j--; k--; if(j>0&&k<0){ l=min(j,-k); ans+=l; j-=l; k+=l; } if(k>0&&j<0){ l=min(-j,k); ans+=l; k-=l; j+=l; } ans+=abs(j)+abs(k); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...