Submission #971975

#TimeUsernameProblemLanguageResultExecution timeMemory
971975Halym2007Palembang Bridges (APIO15_bridge)C++17
22 / 100
32 ms6616 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define sz size() const int N = 1e5 + 5; ll jogap, a[N], b[N]; int n, k; char oy[N], of[N]; vector <ll> v; ll hasapla (ll x, ll y) { ll ret = 0; for (int i = 1; i <= n; ++i) { if (oy[i] == of[i]) { continue; } else { ll gosh = abs (a[i] - x) + abs (x - b[i]); ll gosh1 = 2e18; if (k > 1) gosh1 = abs (a[i] - y) + abs (y - b[i]); ret += min (gosh, gosh1); } } return ret; } int main () { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); // freopen ("input.txt", "r", stdin); cin >> k >> n; for (int i = 1; i <= n; ++i) { cin >> oy[i] >> a[i] >> of[i] >> b[i]; } ll goshmaly = 0; jogap = 2e18; for (int i = 1; i <= n; ++i) { if (oy[i] == of[i]) { goshmaly += abs (a[i] - b[i]); } else { v.pb (a[i]);v.pb (b[i]); goshmaly++; } } if (!v.empty()) { sort (v.begin(), v.end()); goshmaly += hasapla (v[(int)v.sz / 2], -1); } if (jogap == 2e18) jogap = 0; cout << jogap + goshmaly; }
#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...