Submission #883550

#TimeUsernameProblemLanguageResultExecution timeMemory
883550SalihSahinPalembang Bridges (APIO15_bridge)C++14
22 / 100
49 ms4316 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define mp make_pair using namespace std; typedef long long ll; const int inf = 1e9 * 2; const int mod = 1e9 + 7; const int N = 3e4 + 5; ll dis(pair<ll, ll> i, ll p){ if(i.first <= p && i.second >= p) return 0; else if(i.first > p) return i.first - p; else return p - i.second; } vector<pair<int, int> > a; ll check(int m){ ll val = 0; for(auto itr: a){ val += dis(itr, m) * 2; } return val; } int32_t main(){ ios_base::sync_with_stdio(false), cin.tie(); int k, n; cin>>k>>n; ll ans = 0; char h, o; int hx, ox; for(int i = 0; i < n; i++){ cin>>h>>hx>>o>>ox; if(h != o){ if(hx > ox) swap(hx, ox); a.pb(mp(hx, ox)); } ans += abs(hx - ox); } ans += a.size(); if(!a.size()){ cout<<ans<<endl; } else if(k == 1){ int l = 0, r = mod; while(l < r){ int m = (l + r)/2; ll x = check(m), y = check(m+1); if(x <= y) r = m; else l = m + 1; } ans += check(l); cout<<ans<<endl; } else{ cout<<0<<endl; } 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...