Submission #958203

#TimeUsernameProblemLanguageResultExecution timeMemory
958203riaritiPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms600 KiB
#line 1 "Palembang_Bridges.cpp" #include <bits/stdc++.h> #ifdef local #define dbg(__VA_ARGS__) \ std::cerr << "[DBG|" << __LINE__ << "]: " << __VA_ARGS__ << std::endl; #define cerr(__VA_ARGS__) std::cerr << __VA_ARGS__; #else #define dbg(...) #define cerr(...) #endif const auto vec_out = [](const std::vector<int> &cc) { dbg("vector: "); for (auto x : cc) { cerr(x << " "); } cerr("\n"); }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int K, N; std::cin >> K >> N; std::vector<std::tuple<char, int, char, int>> PSQT(N); for (auto &[P, S, Q, T] : PSQT) { std::cin >> P >> S >> Q >> T; } std::vector<int> pos; for (auto [P, S, Q, T] : PSQT) { pos.push_back(S); pos.push_back(T); } std::sort(pos.begin(), pos.end()); std::int64_t ans = LLONG_MAX; for (int m = N; m <= N + 1; m++) { std::int64_t res = 0; for (auto [P, S, Q, T] : PSQT) { if (P == Q) { res += std::abs(static_cast<std::int64_t>(S - T)); continue; } res += static_cast<std::int64_t>(std::abs(S - pos[m])) + std::abs(T - pos[m]) + 1; } ans = std::min(ans, res); } std::cout << ans << "\n"; return 0; } /* #include <bits/stdc++.h> #ifdef local #define dbg(__VA_ARGS__) \ std::cerr << "[DBG|" << __LINE__ << "]: " << __VA_ARGS__ << std::endl; #define cerr(__VA_ARGS__) std::cerr << __VA_ARGS__; #else #define dbg(...) #define cerr(...) #endif const auto vec_out = [](const std::vector<int> &cc) { dbg("vector: "); for (auto x : cc) { cerr(x << " "); } cerr("\n"); }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int K, N; std::cin >> K >> N; std::vector<std::tuple<char, std::int64_t, char, std::int64_t>> PSQT(N); for (auto &[P, S, Q, T] : PSQT) { std::cin >> P >> S >> Q >> T; } std::int64_t ans = 0; std::vector<std::pair<std::int64_t, std::int64_t>> HW; for (auto [P, S, Q, T] : PSQT) { if (P == Q) { ans += std::abs(T - S); continue; } HW.emplace_back(S, T); } auto f = [&](int x) { std::int64_t ans = 0; for (auto [S, T] : HW) { // +1 for bridge ans += std::abs(S - x) + std::abs(T - x) + 1; } return ans; }; std::int64_t l = 0, r = 1'000'000'001; while (l <= r) { auto m = l + (r - l) / 2; if (!(f(m) <= f(m + 1))) { l = m + 1; } else { r = m - 1; } } ans += f(l); std::cout << ans << "\n"; return 0; } */

Compilation message (stderr)

Palembang_Bridges.cpp: In lambda function:
Palembang_Bridges.cpp:14:15: warning: unused variable 'x' [-Wunused-variable]
#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...