제출 #650662

#제출 시각아이디문제언어결과실행 시간메모리
650662AmirHPalembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms328 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define pb push_back #define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define pii pair<int, int> const int MAX_N=2e5+25; ll res = 0; ll k, n; vector<ll> fi, sec; set<ll> s; ll suf[MAX_N]; ll pre[MAX_N]; void solve() { sort(fi.begin(), fi.end()); sort(sec.begin(), sec.end()); for(int i = fi.size(); i >= 1; i--) { suf[i] = suf[i + 1] + fi[i - 1]; } for(int i = 0; i < sec.size(); i++) { pre[i + 1] = sec[i] + pre[i]; } ll mini = 1e18; for(auto x : s) { ll sum = 0; int pos = upper_bound(fi.begin(), fi.end(), x) - fi.begin() + 1; sum += suf[pos] - ((fi.size() - pos + 1) * x); pos = lower_bound(sec.begin(), sec.end(), x) - sec.begin(); sum += (pos * x) - pre[pos]; mini = min(sum, mini); } cout << res + 2 * mini; } void input() { cin >> k >> n; for(int i = 1; i <= n; i++) { char a, b; ll x, y; cin >> a >> x >> b >> y; res += abs(x - y); if(a != b) { res++; fi.pb(min(x, y)); sec.pb(max(x, y)); s.insert(x); s.insert(y); } } } int main() { faster; input(); solve(); }

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

bridge.cpp: In function 'void solve()':
bridge.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int i = 0; i < sec.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...