Submission #602565

#TimeUsernameProblemLanguageResultExecution timeMemory
602565snasibov05Palembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms296 KiB
#include <bits/stdc++.h> using namespace std; #define oo 1000000000 int main() { int k, n; cin >> k >> n; int ans = 0; vector<int> arr; for (int i = 0; i < n; ++i){ char t1, t2; int x1, x2; cin >> t1 >> x1 >> t2 >> x2; if (t1 == t2) ans += abs(x2 - x1); else arr.push_back(x1), arr.push_back(x2); } if (arr.size() == 0){ cout << ans << "\n"; return 0; } sort(arr.begin(), arr.end()); vector<int> pref(arr.size()); pref[0] = arr[0]; for (int i = 1; i < arr.size(); ++i) pref[i] = pref[i-1] + arr[i]; vector<int> suf(arr.size()); suf.back() = arr.back(); for (int i = arr.size() - 2; i >= 0; --i) suf[i] = suf[i+1] + arr[i]; int mn = oo; for (int i = 0; i < arr.size(); ++i){ int cur = 0; if (i != 0) cur += (i-1) * arr[i] - pref[i-1]; if (i != arr.size() - 1) cur += suf[i+1] - (arr.size() - i) * arr[i]; mn = min(mn, cur); } ans += arr.size() / 2; ans += mn; cout << ans << "\n"; return 0; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 1; i < arr.size(); ++i) pref[i] = pref[i-1] + arr[i];
      |                     ~~^~~~~~~~~~~~
bridge.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 0; i < arr.size(); ++i){
      |                     ~~^~~~~~~~~~~~
bridge.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if (i != arr.size() - 1) cur += suf[i+1] - (arr.size() - i) * arr[i];
      |             ~~^~~~~~~~~~~~~~~~~
#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...