Submission #348034

#TimeUsernameProblemLanguageResultExecution timeMemory
348034ThinGarfieldPalembang Bridges (APIO15_bridge)C++11
22 / 100
49 ms4328 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define F first #define S second using pip = pair<int, pii>; // (s+t)/2, s, t constexpr ll sc = 4; constexpr ll maxx = 2e9 + 18; constexpr int maxn = 1e5 + 18; ll cost; int n, k; vector<ll> endpts; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> k >> n; for (int i = 0; i < n; i++) { char s1, t1; int s, t; cin >> s1 >> s >> t1 >> t; if (s1 == t1) { cost += sc * abs(t - s); // cout << '+' << sc * abs(t - s) << '\n'; } else { endpts.push_back(sc * s); endpts.push_back(sc * t); } } sort(endpts.begin(), endpts.end()); if (k == 1) { int eps = endpts.size() / 2; if (eps != 0) { int bloc = (endpts[eps] + endpts[eps - 1]) / 2; for (int x : endpts) { cost += abs(bloc - x); // cout << '+' << abs(bloc - x) << '\n'; } cost += (eps * sc); // cout << '+' << eps * sc << '\n'; } cout << cost / sc << '\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...