Submission #1110246

#TimeUsernameProblemLanguageResultExecution timeMemory
1110246IcelastPalembang Bridges (APIO15_bridge)C++17
22 / 100
34 ms5324 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void solve(){ ll k, n; cin >> k >> n; vector<ll> a(1); ll ans = 0; for(int i = 1; i <= n; i++){ char s1, s2; int l, r; cin >> s1 >> l >> s2 >> r; if(l > r) swap(l, r); if(s1 == s2){ ans += r-l; }else{ a.push_back(l); a.push_back(r); } } sort(a.begin()+1, a.end()); n = a.size()-1; ans += n/2; if(k == 1){ int m = (n+1)/2; for(int i = 1; i <= n; i++){ ans += abs(a[m]-a[i]); } cout << ans; return; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#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...