# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716510 | Baytoro | Coin Collecting (JOI19_ho_t4) | C++17 | 58 ms | 6580 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;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e5+5;
int n,m,k;
int a[N][2];
void solve(){
cin>>n;
int ans=0;
for(int i=0;i<2*n;i++){
int x,y;cin>>x>>y;
if(x>n) ans+=(x-n),x=n;
else if(x<1) ans+=(1-x),x=1;
if(y>2) ans+=(y-2),y=2;
else if(y<1) ans+=(1-y),y=1;
x--,y--; a[x][y]++;
}
int l=0,r=0;
for(int i=0;l<n || r<n;){
while(!a[i][0] && !a[i][1]) i++;
if(a[i][0] && l<=i) ans+=(i-l++),a[i][0]--;
else if(a[i][1] && r<=i) ans+=(i-r++),a[i][1]--;
else if(a[i][0] && r<=i) ans+=(1+i-r++),a[i][0]--;
else if(a[i][1] && l<=i) ans+=(1+i-l++),a[i][1]--;
else{
a[i+1][0]+=a[i][0];
a[i+1][1]+=a[i][1];
ans+=(a[i][0]+a[i][1]);
i++;
}
}
cout<<ans;
}
main(){
//fopn("team");
ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
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... |