Submission #521174

#TimeUsernameProblemLanguageResultExecution timeMemory
521174SharkyPalembang Bridges (APIO15_bridge)C++17
22 / 100
38 ms4172 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0); cin.tie(0); int sameside = 0, k, n, m = 0, ans = 0; cin >> k >> n; vector<int> v(2 * n + 5); for (int i = 1; i <= n; i++) { char p, q; int s, t; cin >> p >> s >> q >> t; if (p == q) sameside += abs(s - t); else { m++; v[m] = s; m++; v[m] = t; } } if (k == 1) { sort(v.begin() + 1, v.begin() + m + 1); int bridge = v[(m + 1) / 2]; for (int i = 1; i <= m; i += 2) { ans += abs(bridge - v[i]) + abs(bridge - v[i + 1]) + 1; } cout << ans + sameside << "\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...