Submission #1054198

#TimeUsernameProblemLanguageResultExecution timeMemory
1054198idasPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr) #define FOR(i, begin, end) for(int i=(begin); i<(end); i++) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int N=1e5+10; int k, n; ll ans; vector<ll> a; int main() { FAST_IO; cin >> k >> n; FOR(i, 0, n) { char c1, c2; int x1, x2; cin >> c1 >> x1 >> c2 >> x2; if(c1==c2) { ans+=abs(x1-x2); } else { a.pb(x1); a.pb(x2); } } sort(a.begin(), a.end()); n=a.size(); ans+=n/2; if(k==1) { ll sm=0, cn=0; FOR(i, 0, n/2) sm+=a[i], cn++; ans+=a[n/2]*cn-sm; sm=0; cn=0; FOR(i, n/2+1, n) sm+=a[i], cn++; ans+=sm-a[n/2]*cn; cout << ans; } }
#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...