제출 #602944

#제출 시각아이디문제언어결과실행 시간메모리
602944FidanPalembang Bridges (APIO15_bridge)C++17
0 / 100
2 ms312 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf=(1e18)+10; int main(){ ll k, n; cin>>k>>n; if(k==1){ ll sum=0, i; vector<pair<ll, ll>> v; for(i=0; i<n; i++){ char c1, c2; ll i1, i2; cin>>c1>>i1>>c2>>i2; sum+=abs(i1-i2); if(c1!=c2){ if(c1=='B'){ swap(i1, i2); } sum++; v.push_back({i1, i2}); } } ll sum1=inf; for(i=0; i<n; i++){ ll s=0; for(auto p: v){ ll a1=p.first, a2=p.second; if(min(a1, a2)>i){ s+=2*(min(a1, a2)-i); } else if(max(a1, a2)<i){ s+=2*(i-max(a1, a2)); } } sum1=min(sum1, s); } cout<<sum+sum1; } return 0; }
#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...