Submission #389786

#TimeUsernameProblemLanguageResultExecution timeMemory
389786milleniumEeeePalembang Bridges (APIO15_bridge)C++14
22 / 100
48 ms6040 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pii pair<int, int> #define pb push_back #define szof(s) (int)s.size() #define all(s) s.begin(), s.end() #define fastInp ios_base::sync_with_stdio(0); cin.tie(0); #define int long long using namespace std; const int MAXN = (int)2e5 + 5; const int INF = 1e18; pair <char, int> st[MAXN]; pair <char, int> fn[MAXN]; bool ok(int pos) { return (st[pos].first == fn[pos].first); } signed main() { fastInp; int n, k; cin >> k >> n; for (int i = 1; i <= n; i++) { cin >> st[i].fr >> st[i].sc >> fn[i].fr >> fn[i].sc; } if (k == 1) { int side = 0; int bridge = 0; vector <int> x; for (int i = 1; i <= n; i++) { if (ok(i)) { side += abs(st[i].sc - fn[i].sc); } else { x.pb(st[i].sc); x.pb(fn[i].sc); } } sort(all(x)); int opt = x[szof(x) / 2 - 1]; for (int el : x) { bridge += abs(opt - el); } cout << side + szof(x) / 2 + bridge << endl; } else if (k == 2) { } } /* 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...