Submission #249624

#TimeUsernameProblemLanguageResultExecution timeMemory
249624AMO5Palembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms520 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define eb emplace_back #define mt make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define MOD 1000000007 typedef long long ll; typedef pair <int, int> ii; typedef pair <ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef long double ld; bool DEBUG=0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int k,n; vll coor; vector<pll>str; cin >> k >> n; ll ans = 0ll; for(int i=0; i<n; i++){ char p,q; ll s,t; cin >> p >> s >> q >> t; if(p==q){ ans += abs(s-t); }else{ if(s>t)swap(s,t); ans+=t-s+1ll; str.eb(s,t); } } n=sz(str); //k=1 for(ii x:str){ coor.eb(x.fi); coor.eb(x.se); } sort(all(coor)); ll bridge1=coor[n-1],bridge2=coor[n]; ll res1=0ll,res2=0ll; for(int i=0; i<n; i++){ if(bridge1<str[i].fi){ res1 += 2ll*(str[i].fi-bridge1); }else if(bridge1>str[i].se){ res1 += 2ll*(bridge1-str[i].se); } if(bridge2<str[i].fi){ res2 += 2ll*(str[i].fi-bridge2); }else if(bridge2>str[i].se){ res2 += 2ll*(bridge2-str[i].se); } } ans += min(res1,res2); cout << ans << '\n'; 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...