This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define N 100001
int m;
vector<ll> x,y;
ll dist(ll p,ll q){
ll o=0;
for(int i=0;i<m;i++){
if((x[i]>=p && p>=y[i]) ||
(x[i]>=q && q>=y[i])) continue;
o+=min(min(abs(p-x[i]),abs(p-y[i]))
,min(abs(q-x[i]),abs(q-y[i])))*2;
}
return o;
}
void solve1(){
char c,d;
ll n,o,p,q,r;
cin>>n;
for(int i=o=0;i<n;i++){
cin>>c>>p>>d>>q;
o+=abs(p-q);
if(c!=d){
o++;
m++;
x.append(max(p,q));
y.append(min(p,q));
}
}
r=0;
for(int j=536870912;j>0;j/=2)
if(dist(r+j,r+j)<=dist(r+j-1,r+j-1))
r+=j;
cout<<o+dist(r,r);
}
void solve2(){
cout<<0<<nl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int t;
cin>>t;
if(t==1) solve1();
else solve2();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |