Submission #739153

#TimeUsernameProblemLanguageResultExecution timeMemory
739153MauvePalembang Bridges (APIO15_bridge)C++14
22 / 100
42 ms2512 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define INF 1e18 ll m,n,l,r,T,i,j,ii,jj,k,D[200005],ans; vector<ll> pos; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>T>>n; ans=INF; for(i=0;i<n;i++){ char a,b; cin>>a>>l>>b>>r; if(a==b) k+=abs(l-r); else{ pos.pb(l); pos.pb(r); k++; } } sort(pos.begin(),pos.end()); n=pos.size(); if(T==1){ for(ll it : pos) k+=abs(pos[n/2]-it); cout<<k; } else{ for(i=0;i<n;i++) D[0]+=abs(pos[0]-pos[i]); for(i=1;i<n;i++) D[i]=D[i-1]+(pos[i]-pos[i-1])*i-(pos[i]-pos[i-1])*(n-i); for(i=0;i<n;i++) for(j=i+1;j<n;j++) ans=min(ans,D[i]+D[j]+k); cout<<ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...