제출 #1123690

#제출 시각아이디문제언어결과실행 시간메모리
1123690ezzzayPalembang Bridges (APIO15_bridge)C++20
0 / 100
4 ms328 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=3e5+5; int dist(int a, int b){ return abs(a-b); } signed main(){ int k,n; cin>>k>>n; vector<pair<int,int>>v; int s=0; vector<int>vc; for(int i=1;i<=n;i++){ char x,y; int a,b; cin>>x>>a>>y>>b; if(x==y){ s+=abs(a-b); } else{ v.pb({a,b}); vc.pb(a); vc.pb(b); } } k=1e9; for(auto a:vc){ int g=0; for(auto p:v){ g+=dist(a,p.ff)+dist(a,p.ss)+1; } k=min(k,g); } if(k==1e9)k=0; cout<<s+k; }
#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...