Submission #699347

#TimeUsernameProblemLanguageResultExecution timeMemory
699347CatalinTPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms320 KiB
#include <vector> #include <iostream> #include <cassert> #include <algorithm> #include <numeric> #include <iostream> #include <set> #include <map> #include <string> #include <unordered_map> #include <functional> #include <bitset> #include <sstream> using namespace std; using int64 = long long; int N, M, K; vector<pair<int64, int64>> segments; vector<int64> X; vector<int64> vec; vector<int> cnt; map<int64, int> idx; int64 solve1brute() { int64 res = (1LL<<60); for (int i = 0; i < N; i++) { int64 cur = 0; for (auto & s : segments) { if (s.second < vec[i]) { cur += 2 * (vec[i] - s.second); } else if (s.second >= vec[i] && s.first <= vec[i]) { // nada } else { cur += 2 * (s.first - vec[i]); } } res = min(res, cur); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int64 res = 0; cin >> N >> K; set<int> uniq; for (int i = 0; i < N; i++) { char z1, z2; int x1, x2; cin >> z1 >> x1 >> z2 >> x2; res += abs(x1 - x2); if (z1 != z2) { segments.emplace_back(min(x1, x2), max(x1, x2)); uniq.insert(x1); uniq.insert(x2); } } if (!size(segments)) { cout << res << "\n"; return 0; } vector<int> vec(begin(uniq), end(uniq)); N = size(vec); for (int i = 0; i < N; i++) { idx[vec[i]] = i; } for (auto & s : segments) { cnt[s.first]++; cnt[s.second]--; } M = size(segments); // need at least one bridge; cout << solve1brute() << "\n"; return 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...