Submission #979710

#TimeUsernameProblemLanguageResultExecution timeMemory
979710tamir1Palembang Bridges (APIO15_bridge)C++17
22 / 100
30 ms5212 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll ans,n,k,i,j,x,y,l,m,a[200005],z,mn=1e18; array<ll,2> b[200005]; char s,t; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> k >> n; for(i=1;i<=n;i++){ cin >> s >> x >> t >> y; if(s==t) ans+=abs(x-y); else{ ans++; l++; a[l]=x; l++; a[l]=y; m++; b[m][0]=x; b[m][1]=y; } } sort(a+1,a+l+1); x=a[(l+1)/2]; if(k==1){ for(i=1;i<=l;i++){ ans+=abs(x-a[i]); } cout << ans; return 0;} for(i=a[1];i<a[l];i++){ for(j=i+1;j<=a[l];j++){ z=0; for(ll g=1;g<=m;g++){ z+=min(abs(i-b[g][0])+abs(i-b[g][1]),abs(j-b[g][0])+abs(j-b[g][1])); } mn=min(mn,z); } } cout << ans+mn; }
#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...