# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
232201 | jamielim | Coin Collecting (JOI19_ho_t4) | C++14 | 86 ms | 6524 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |