Submission #733619

#TimeUsernameProblemLanguageResultExecution timeMemory
733619SanguineChameleonPalembang Bridges (APIO15_bridge)C++17
22 / 100
47 ms6676 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } vector<long long> calc(vector<int> A) { int M = A.size(); vector<long long> res(M); vector<long long> pref(M); pref[0] = A[0]; for (int i = 1; i < M; i++) { pref[i] = pref[i - 1] + A[i]; } for (int i = 2; i <= M; i++) { int mid = A[(i - 1) / 2]; long long left_sum = pref[(i - 1) / 2]; long long right_sum = pref[i - 1] - left_sum; res[i - 1] = abs(1LL * mid * ((i + 1) / 2) - left_sum) + abs(1LL * mid * (i / 2) - right_sum); } return res; } void just_do_it() { int K, N; cin >> K >> N; vector<int> A; long long add = 0; for (int i = 0; i < N; i++) { char P, Q; int S, T; cin >> P >> S >> Q >> T; if (P == Q) { add += abs(S - T); } else { add++; A.push_back(S); A.push_back(T); } } if (A.empty()) { cout << add; return; } sort(A.begin(), A.end()); int M = A.size(); vector<long long> pref = calc(A); reverse(A.begin(), A.end()); vector<long long> suf = calc(A); reverse(suf.begin(), suf.end()); if (K == 1) { cout << pref[M - 1] + add; return; } }
#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...