제출 #958196

#제출 시각아이디문제언어결과실행 시간메모리
958196riaritiPalembang Bridges (APIO15_bridge)C++17
컴파일 에러
0 ms0 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> cc; // for (auto [P, S, Q, T] : PSQT) { // cc.push_back(S); // cc.push_back(T); // } // std::ranges::sort(cc); // cc.erase(std::unique(cc.begin(), cc.end()), cc.end()); // vec_out(cc); // auto compress = [cc](int v) { // return std::distance(cc.begin(), std::ranges::lower_bound(cc, v)); // }; // auto expand = [cc](int v) { return cc[v]; }; // for (auto &[P, S, Q, T] : PSQT) { // S = compress(S); // T = compress(T); // } // dbg("Compressed here"); // for (auto [P, S, Q, T] : PSQT) { // dbg(P << " " << S << " " << Q << " " << T); // } // median => at max 4 possibilites, then sliding window all throughout // optimal to keep one of the points at someones house or office tho std::vector<int> pos; for (auto [P, S, Q, T] : PSQT) { pos.push_back(S); pos.push_back(T); } vec_out(pos); // K = 1 minimized at median since sum is as follows: // // sum of all |Si - x| + |Ti - x| auto m = std::midpoint<int>(0, pos.size()); std::nth_element(pos.begin(), pos.begin() + m, pos.end()); vec_out(pos); auto med = pos[m]; std::int64_t ans = 0; for (auto [P, S, Q, T] : PSQT) { ans += static_cast<std::int64_t>(std::abs(S - med)) + std::abs(T - med); } std::cout << ans << "\n"; return 0; }

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

Palembang_Bridges.cpp: In lambda function:
Palembang_Bridges.cpp:14:15: warning: unused variable 'x' [-Wunused-variable]
Palembang_Bridges.cpp: In function 'int main()':
Palembang_Bridges.cpp:71:19: error: 'midpoint' is not a member of 'std'
Palembang_Bridges.cpp:71:28: error: expected primary-expression before 'int'