Submission #1309236

#TimeUsernameProblemLanguageResultExecution timeMemory
1309236teriyakiiPalembang Bridges (APIO15_bridge)C++20
0 / 100
1 ms428 KiB
//اللهم منزل الكتاب ومجري السحاب وهْازِم الأحزاب، اهزمهم وانصرنا عليهم //اللهم علمنا ما ينفعنا، وانفعنا بما علمتنا، وزدنا علما #include<bits/stdc++.h> #define pb push_back #define el '\n' using namespace std; typedef long long ll; int main() { cin.tie(0)->sync_with_stdio(0); ll ans = 0; int n, k; cin >> k >> n; vector<int> l, r; for (int i = 0; i < n; ++i) { char a, b; int q, t; cin >> a >> q >> b >> t; if (a == b) { ans += abs(q - t); continue; } if (a == 'B') { swap(a, b); swap(q, t); } l.push_back(q); r.push_back(t); } if (k == 1) { vector<int> sorted = l; for (auto i: r)sorted.pb(i); sort(sorted.begin(), sorted.end()); int med = sorted[sorted.size() / 2]; for (int i = 0; i < l.size(); i++) { ans += abs(l[i] - med) + 1 + abs(r[i] - med); } cout << ans; } else { vector<int> sorted = l; sort(sorted.begin(), sorted.end()); int med1 = sorted[sorted.size()/2]; sorted = r; sort(sorted.begin(), sorted.end()); int med2 = sorted[sorted.size()/2]; for (int i = 0; i < l.size(); i++) { ans += min(abs(l[i] - med1) + 1 + abs(r[i] - med1), abs(l[i] - med2) + 1 + abs(r[i] - med2)); } cout << ans; } 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...