This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (auto m : {pos.size() / 2 + 1}) {
std::int64_t res = 0;
for (auto [P, S, Q, T] : PSQT) {
res += static_cast<std::int64_t>(std::abs(S - pos[m])) +
std::abs(T - pos[m]);
}
ans = std::min(ans, res);
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |