# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026153 | snpmrnhlol | Coin Collecting (JOI19_ho_t4) | C++17 | 0 ms | 348 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;
typedef long long ll;
const ll N = 1e5;
struct xy{
ll x,y;
}v[N*2];
ll f[2];
int main(){
ll n,m;
ll ans = 0;
cin>>n;
for(ll i = 0;i < 2*n;i++){
cin>>v[i].x>>v[i].y;
v[i].x--;v[i].y--;
}
sort(v,v + n*2,[&](xy a,xy b){
return a.x < b.x;
});
ll i = 0,j = 0;
ll last = -1;
while(i < n*2){
j = i;
f[0] = 0;f[1] = 0;
if(last == 0)f[0]++;
else if(last == 1)f[1]++;
last = -1;
while(j < n*2 && v[j].x == v[i].x){
ans+=abs(v[j].x - j/2) + min(abs(v[j].y - 0),abs(v[j].y - 1));
if(v[j].y <= 0)f[0]++;
else f[1]++;
j++;
}
if(f[0] > f[1]){
f[0]-=f[1];
ans+=f[0]/2;
if(f[0]%2 == 1){
last = 0;
}
}else{
f[1]-=f[0];
ans+=f[1]/2;
if(f[1]%2 == 1){
last = 1;
}
}
///i -> j - 1 fuck my wife
i = j;
}
cout<<ans<<'\n';
return 0;
}
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... |