Submission #380489

#TimeUsernameProblemLanguageResultExecution timeMemory
380489jass921026Palembang Bridges (APIO15_bridge)C++14
22 / 100
55 ms2264 KiB
#include<bits/stdc++.h> using namespace std; #define jizz ios_base::sync_with_stdio(false);cin.tie(NULL); typedef long long ll; typedef pair<int,int> pii; #define F first #define S second #define ALL(x) (x).begin(),(x).end() #define pb push_back #define mkp make_pair int abs(int x){ return x>0?x:-x; } vector<pii> segs; vector<int> pos; int main(){ jizz int k, n; cin>>k>>n; ll ans=0; for(int i=0;i<n;i++){ char p, q; int s, t; cin>>p>>s>>q>>t; if(s>t) swap(s,t); ans+=(t-s); if(p!=q) { ans++; segs.pb(mkp(s,t)); pos.pb(s); pos.pb(t); } } if(pos.empty()){ cout<<ans<<"\n"; return 0; } sort(ALL(pos)); int sz=pos.size(); int bp=pos[sz/2]; for(int i=0;i<sz/2;i++){ if(segs[i].S<bp) ans+=2*(bp-segs[i].S); else if(segs[i].F>bp) ans+=2*(segs[i].F-bp); } cout<<ans<<"\n"; return 0; } /* 1 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */
#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...