Submission #602984

#TimeUsernameProblemLanguageResultExecution timeMemory
602984FidanPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms340 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; vector<ll> v1; for(i=0; i<n; i++){ char c1, c2; ll i1, i2; cin>>c1>>i1>>c2>>i2; sum+=abs(i1-i2); if(c1!=c2){ sum++; v.push_back({i1, i2}); v1.push_back(i1); v1.push_back(i2); } } sort(v1.begin(), v1.end()); k=v1.size(); ll cvb=v1[k/2]; for(auto p: v){ ll a1=p.first, a2=p.second; if(min(a1, a2)>cvb) sum+=2*(min(a1, a2)-cvb); else if(max(a1, a2)<cvb) sum+=2*(cvb-max(a1, a2)); } cout<<sum; } 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...