Submission #989292

#TimeUsernameProblemLanguageResultExecution timeMemory
989292aykhnPalembang Bridges (APIO15_bridge)C++17
22 / 100
53 ms9412 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F3F3F3F3F signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int k, n, S = 0; cin >> k >> n; vector<int> id = {0}, L, pL, sL, R, pR, sR; for (int i = 0; i < n; i++) { char a, b; int l, r; cin >> a >> l >> b >> r; if (l > r) swap(l, r); S += r - l; if (a != b) id.push_back(l), id.push_back(r), L.push_back(r), R.push_back(l); } sort(id.begin(), id.end()), sort(L.begin(), L.end()), sort(R.begin(), R.end()); id.resize(unique(id.begin(), id.end()) - id.begin()); pL = sL = L, pR = sR = R; for (int i = 1; i < pL.size(); i++) pL[i] += pL[i - 1]; for (int i = 1; i < pR.size(); i++) pR[i] += pR[i - 1]; for (int i = (int)sL.size() - 2; i >= 0; i--) sL[i] += sL[i + 1]; for (int i = (int)sR.size() - 2; i >= 0; i--) sR[i] += sR[i + 1]; int res = inf; for (int i : id) { int sum = 0, pi = lower_bound(L.begin(), L.end(), i) - L.begin() - 1, si = upper_bound(R.begin(), R.end(), i) - R.begin(), cnt = 0; if (0 <= pi && pi < L.size()) sum += i * (pi + 1) - pL[pi]; if (0 <= si && si < R.size()) sum += sR[si] - i * ((int)R.size() - si); res = min(res, 2 * sum + S + (int)L.size()); } cout << res << '\n'; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:27:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i = 1; i < pL.size(); i++) pL[i] += pL[i - 1];
      |                   ~~^~~~~~~~~~~
bridge.cpp:28:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for (int i = 1; i < pR.size(); i++) pR[i] += pR[i - 1];
      |                   ~~^~~~~~~~~~~
bridge.cpp:35:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (0 <= pi && pi < L.size()) sum += i * (pi + 1) - pL[pi];
      |                    ~~~^~~~~~~~~~
bridge.cpp:36:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     if (0 <= si && si < R.size()) sum += sR[si] - i * ((int)R.size() - si);
      |                    ~~~^~~~~~~~~~
bridge.cpp:34:128: warning: unused variable 'cnt' [-Wunused-variable]
   34 |     int sum = 0, pi = lower_bound(L.begin(), L.end(), i) - L.begin() - 1, si = upper_bound(R.begin(), R.end(), i) - R.begin(), cnt = 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...