제출 #114118

#제출 시각아이디문제언어결과실행 시간메모리
114118fedoseevtimofeyPalembang Bridges (APIO15_bridge)C++14
8 / 100
2041 ms10972 KiB
#include <bits/stdc++.h> #define int long long using namespace std; typedef long long ll; typedef long double ld; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int k, n; cin >> k >> n; vector <pair <int, int>> a; ll res = 0; vector <pair <int, int>> e; vector <int> c; ll cur = 0; int cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; ++i) { char p, q; int x, y; cin >> p >> x >> q >> y; res += abs(x - y); if (x > y) swap(x, y); if (p != q) { e.push_back({x, -1}); e.push_back({y, 1}); a.emplace_back(x, y); cur += 2 * x; ++cnt1; ++res; } c.push_back(x); c.push_back(y); } sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin()); sort(e.begin(), e.end()); /*assert(k == 1); ll ans = cur + res; for (int i = 0; i < (int)e.size(); ++i) { if (i) { cur -= 2LL * cnt1 * (e[i].first - e[i - 1].first); cur += 2LL * cnt2 * (e[i].first - e[i - 1].first); } if (e[i].second == -1) --cnt1; else ++cnt2; ans = min(ans, res + cur); } cout << ans << '\n';*/ ll ans = 1e18; for (auto x : c) { ll cur = res; for (auto p : a) { if (p.first <= x && x <= p.second) continue; cur += 2 * min(abs(p.first - x), abs(p.second - x)); } ans = min(ans, cur); } cout << ans << '\n'; }

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

bridge.cpp: In function 'int main()':
bridge.cpp:23:19: warning: unused variable 'cnt2' [-Wunused-variable]
     int cnt1 = 0, cnt2 = 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...