제출 #979726

#제출 시각아이디문제언어결과실행 시간메모리
979726tamir1Palembang Bridges (APIO15_bridge)C++17
31 / 100
2079 ms5120 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=1;i<l;i++){ for(j=i+1;j<=l;j++){ z=0; for(ll g=1;g<=m;g++){ z+=min(abs(a[i]-b[g][0])+abs(a[i]-b[g][1]),abs(a[j]-b[g][0])+abs(a[j]-b[g][1])); } mn=min(mn,z); } } if(mn==1e18) mn=0; 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...