제출 #257524

#제출 시각아이디문제언어결과실행 시간메모리
257524KoD여행하는 상인 (APIO17_merchant)C++17
100 / 100
224 ms3320 KiB
#line 1 "main.cpp" /** * @title Template */ #include <iostream> #include <algorithm> #include <utility> #include <numeric> #include <vector> #include <array> #include <queue> #include <cassert> #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/chmin_chmax.cpp" template <class T, class U> constexpr bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template <class T, class U> constexpr bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } /** * @title Chmin/Chmax */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/range.cpp" #line 4 "/Users/kodamankod/Desktop/Programming/Library/other/range.cpp" class range { public: class iterator { private: int64_t M_position; public: constexpr iterator(int64_t position) noexcept: M_position(position) { } constexpr void operator ++ () noexcept { ++M_position; } constexpr bool operator != (iterator other) const noexcept { return M_position != other.M_position; } constexpr int64_t operator * () const noexcept { return M_position; } }; class reverse_iterator { private: int64_t M_position; public: constexpr reverse_iterator(int64_t position) noexcept: M_position(position) { } constexpr void operator ++ () noexcept { --M_position; } constexpr bool operator != (reverse_iterator other) const noexcept { return M_position != other.M_position; } constexpr int64_t operator * () const noexcept { return M_position; } }; private: const iterator M_first, M_last; public: constexpr range(int64_t first, int64_t last) noexcept: M_first(first), M_last(std::max(first, last)) { } constexpr iterator begin() const noexcept { return M_first; } constexpr iterator end() const noexcept { return M_last; } constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(*M_last - 1); } constexpr reverse_iterator rend() const noexcept { return reverse_iterator(*M_first - 1); } }; /** * @title Range */ #line 2 "/Users/kodamankod/Desktop/Programming/Library/other/rev.cpp" #include <type_traits> #include <iterator> #line 6 "/Users/kodamankod/Desktop/Programming/Library/other/rev.cpp" template <class T> class rev_impl { public: using iterator = typename std::decay<T>::type::reverse_iterator; private: const iterator M_begin; const iterator M_end; public: constexpr rev_impl(T &&cont) noexcept: M_begin(std::rbegin(cont)), M_end(std::rend(cont)) { } constexpr iterator begin() const noexcept { return M_begin; } constexpr iterator end() const noexcept { return M_end; } }; template <class T> constexpr decltype(auto) rev(T &&cont) { return rev_impl<T>(std::forward<T>(cont)); } /** * @title Reverser */ #line 18 "main.cpp" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; int main() { i32 N, M, K; std::cin >> N >> M >> K; std::vector<std::vector<i32>> buy(N, std::vector<i32>(K)); std::vector<std::vector<i32>> sell(N, std::vector<i32>(K)); for (auto i: range(0, N)) { for (auto k: range(0, K)) { std::cin >> buy[i][k] >> sell[i][k]; } } std::vector<std::vector<i32>> gain(N, std::vector<i32>(N)); for (auto i: range(0, N)) { for (auto j: range(0, N)) { for (auto k: range(0, K)) { if (sell[j][k] != -1 && buy[i][k] != -1) { chmax(gain[i][j], - buy[i][k] + sell[j][k]); } } } } std::vector<std::vector<i32>> cost(N, std::vector<i32>(N, inf32)); for (auto i: range(0, N)) { cost[i][i] = 0; } for (auto i: range(0, M)) { i32 u, v, c; std::cin >> u >> v >> c; --u; --v; cost[u][v] = c; } for (auto k: range(0, N)) { for (auto i: range(0, N)) { for (auto j: range(0, N)) { chmin(cost[i][j], cost[i][k] + cost[k][j]); } } } i64 ok = 0, ng = (i64) inf32; while (ng - ok > 1) { i64 md = (ok + ng) / 2; std::vector<std::vector<i64>> dist(N, std::vector<i64>(N, -inf64)); for (auto i: range(0, N)) { for (auto j: range(0, N)) { if (cost[i][j] != inf32 && i != j) { dist[i][j] = gain[i][j] - md * cost[i][j]; } } } for (auto k: range(0, N)) { for (auto i: range(0, N)) { for (auto j: range(0, N)) { chmax(dist[i][j], dist[i][k] + dist[k][j]); } } } bool flag = false; for (auto i: range(0, N)) { if (dist[i][i] >= 0) { flag = true; break; } } (flag ? ok : ng) = md; } std::cout << ok << '\n'; return 0; }

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

main.cpp: In function 'int main()':
main.cpp:54:13: warning: unused variable 'i' [-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...