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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll k,n;
cin>>k>>n;
vector<char>p(n),q(n);
vector<ll>s(n),t(n);
set<ll>st;
for(ll i=0;i<n;i++){
cin>>p[i]>>s[i]>>q[i]>>t[i];
if(s[i]>t[i]) swap(s[i],t[i]);
st.insert(s[i]);
st.insert(t[i]);
}
ll ans=1e18;
for(auto x:st){
for(auto y:st){
ll cur=0;
for(ll i=0;i<n;i++){
if(p[i]==q[i]){
cur+=t[i]-s[i];
}
else{
ll c1=abs(s[i]-x)+abs(t[i]-x),c2=abs(s[i]-y)+abs(t[i]-y);
cur+=min(c1,c2)+1;
}
}
ans=min(ans,cur);
}
}
cout<<ans;
}
# | 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... |