제출 #641955

#제출 시각아이디문제언어결과실행 시간메모리
641955gun_ganPalembang Bridges (APIO15_bridge)C++17
22 / 100
51 ms3780 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 5; int k, n; ll same_side = 0, l = 0, r = 0, p[N], s[N], ans = 1e18; vector<pair<int,int>> v; priority_queue<int> lf; priority_queue<int, vector<int>, greater<int>> rg; void push(int x) { if(lf.empty() || x <= lf.top()) { lf.push(x); l += x; } else { rg.push(x); r += x; } if((int)lf.size() - 1 > rg.size()) { int t = lf.top(); l -= t; r += t; lf.pop(); rg.push(t); } else if(lf.size() < rg.size()) { int t = rg.top(); r -= t; l += t; rg.pop(); lf.push(t); } } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> k >> n; for(int i = 0; i < n; i++) { char a, b; int x, y; cin >> a >> x >> b >> y; if(a == b) { same_side += abs(x - y); } else { v.push_back({x, y}); } } sort(v.begin(), v.end(), [&](auto x, auto y){ return x.first + x.second < y.first + y.second; }); for(int i = 0; i < v.size(); i++) { push(v[i].first); push(v[i].second); p[i] = r - l; } if(k == 1) { cout << same_side + p[v.size() - 1] + v.size() << '\n'; return 0; } while(!lf.empty()) lf.pop(); while(!rg.empty()) rg.pop(); l = 0, r = 0; for(int i = v.size() - 1; i > 0; i--) { push(v[i].first); push(v[i].second); ans = min(ans, r - l + p[i - 1]); } cout << same_side + ans + v.size() << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

bridge.cpp: In function 'void push(int)':
bridge.cpp:22:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  if((int)lf.size() - 1 > rg.size()) {
      |     ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0; i < v.size(); 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...