結果
問題 | No.1104 オンライン点呼 |
ユーザー | Pachicobue |
提出日時 | 2020-07-04 00:44:10 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 8,933 bytes |
コンパイル時間 | 2,428 ms |
コンパイル使用メモリ | 218,488 KB |
実行使用メモリ | 32,956 KB |
最終ジャッジ日時 | 2024-09-17 05:23:18 |
合計ジャッジ時間 | 4,698 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 82 ms
31,416 KB |
testcase_02 | AC | 81 ms
31,444 KB |
testcase_03 | AC | 77 ms
31,264 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 45 ms
19,512 KB |
testcase_08 | AC | 19 ms
9,600 KB |
testcase_09 | AC | 104 ms
32,956 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 33 ms
14,620 KB |
testcase_12 | AC | 48 ms
19,868 KB |
testcase_13 | AC | 30 ms
13,172 KB |
testcase_14 | AC | 4 ms
6,944 KB |
testcase_15 | AC | 54 ms
21,332 KB |
testcase_16 | WA | - |
testcase_17 | AC | 43 ms
17,100 KB |
testcase_18 | AC | 56 ms
21,180 KB |
testcase_19 | AC | 68 ms
26,120 KB |
testcase_20 | AC | 74 ms
28,000 KB |
testcase_21 | AC | 75 ms
28,188 KB |
testcase_22 | AC | 62 ms
23,796 KB |
testcase_23 | AC | 50 ms
19,228 KB |
testcase_24 | AC | 21 ms
10,112 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using ll = long long; using uint = unsigned int; using ull = unsigned long long; using ld = long double; template<typename T> using max_heap = std::priority_queue<T>; template<typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; constexpr int popcount(const ull v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const ull v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const ull v) { return __builtin_ffsll(v); } constexpr int clog(const ull v) { return v ? log2p1(v - 1) : 0; } constexpr ull ceil2(const ull v) { return 1ULL << clog(v); } constexpr ull floor2(const ull v) { return v ? (1ULL << (log2p1(v) - 1)) : 0ULL; } constexpr bool btest(const ull mask, const int ind) { return (mask >> ind) & 1ULL; } template<typename T> void bset(T& mask, const int ind) { mask |= ((T)1 << ind); } template<typename T> void breset(T& mask, const int ind) { mask &= ~((T)1 << ind); } template<typename T> void bflip(T& mask, const int ind) { mask ^= ((T)1 << ind); } template<typename T> void bset(T& mask, const int ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; constexpr ull TEN(const int n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; } template<typename F> struct fix : F { fix(F&& f) : F{std::forward<F>(f)} {} template<typename... Args> auto operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; class printer { public: printer(std::ostream& os_ = std::cout) : os{os_} {} template<typename T> int operator()(const T& v) { return os << v, 0; } template<typename T> int operator()(const std::vector<T>& vs) { for (int i = 0; i < (int)vs.size(); i++) { os << (i ? " " : ""), this->operator()(vs[i]); } return 0; } template<typename T> int operator()(const std::vector<std::vector<T>>& vss) { for (int i = 0; i < (int)vss.size(); i++) { os << (0 <= i or i + 1 < (int)vss.size() ? "\n" : ""), this->operator()(vss[i]); } return 0; } template<typename T, typename... Args> int operator()(const T& v, const Args&... args) { return this->operator()(v), os << ' ', this->operator()(args...), 0; } template<typename... Args> int ln(const Args&... args) { return this->operator()(args...), os << '\n', 0; } template<typename... Args> int el(const Args&... args) { return this->operator()(args...), os << std::endl, 0; } template<typename... Args> int fmt(const std::string& s, const Args&... args) { return rec(s, 0, args...); } private: int rec(const std::string& s, int index) { return os << s.substr(index, s.size()), 0; } template<typename T, typename... Args> int rec(const std::string& s, int index, const T& v, const Args&... args) { return index == s.size() ? 0 : s[index] == '%' ? (this->operator()(v), rec(s, index + 1, args...)) : (os << s[index], rec(s, index + 1, v, args...)); } std::ostream& os; }; printer out; template<typename T, typename F> std::vector<T> generated(const int n, F f) { std::vector<T> ans(n); return std::generate(ans.begin(), ans.end(), f), ans; } std::vector<int> ioted(const int n, const int offset = 0) { std::vector<int> ans(n); return std::iota(ans.begin(), ans.end(), offset), ans; } template<typename Vs> Vs reversed(const Vs& vs) { auto ans = vs; return std::reverse(ans.begin(), ans.end()), ans; } template<typename T, typename F = std::less<T>> std::vector<T> sorted(const std::vector<T>& vs, F comp = F{}) { auto ans = vs; return std::sort(ans.begin(), ans.end(), comp), ans; } template<typename F> std::vector<int> sorted_iota(const int n, F comp = F{}, const int offset = 0) { return sorted(ioted(n, offset), comp); } class scanner { public: scanner(std::istream& is_ = std::cin) : is{is_} { is.tie(nullptr), std::ios::sync_with_stdio(false); } template<typename T> T val() { static T v; return is >> v, v; } template<typename T> T val(const T offset) { return val<T>() - offset; } template<typename T> std::vector<T> vec(const int n) { return generated<T>(n, [&] { return val<T>(); }); } template<typename T> std::vector<T> vec(const int n, const T offset) { return generated<T>(n, [&] { return val<T>(offset); }); } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1) { return generated<std::vector<T>>(n0, [&] { return vec<T>(n1); }); } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1, const T offset) { return generated<std::vector<T>>(n0, [&] { return vec<T>(n1, offset); }); } template<typename... Args> auto tup() { return std::tuple<std::decay_t<Args>...>{val<Args>()...}; } template<typename... Args> auto tup(const Args&... offsets) { return std::tuple<std::decay_t<Args>...>{val<Args>(offsets)...}; } private: std::istream& is; }; scanner in; # define SHOW(...) static_cast<void>(0) template<typename T, int n, int i = 0> auto make_v(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], make_v<T, n, i + 1>(szs, x)); } } template<typename T = int> struct edge { using cost_type = T; int u, v; T c; edge(const int u_, const int v_) : u{u_}, v{v_}, c{1} {} edge(const int u_, const int v_, const T& c_) : u{u_}, v{v_}, c{c_} {} operator int() const { return v; } int from() const { return u; } int to() const { return v; } T cost() const { return c; } friend std::ostream& operator<<(std::ostream& os, const edge& e) { return os << e.u << "->" << e.v << ":" << e.c; } }; template<typename Edge> class base_graph { public: base_graph(const int n) : sz{n}, es(n), res(n) {} void add_edge(const int u, const int v, const bool bi = false) { es[u].emplace_back(u, v), res[v].emplace_back(v, u); if (bi) { es[v].emplace_back(v, u), res[u].emplace_back(u, v); } } template<typename Cost> void add_edge(const int u, const int v, const Cost& c, const bool bi = false) { es[u].emplace_back(u, v, c), res[v].emplace_back(v, u, c); if (bi) { es[v].emplace_back(v, u, c), res[u].emplace_back(u, v, c); } } std::vector<Edge>& operator[](const int u) { return es[u]; } const std::vector<Edge>& operator[](const int u) const { return es[u]; } std::vector<Edge>& from(const int u) { return es[u]; } const std::vector<Edge>& from(const int u) const { return es[u]; } std::vector<Edge>& to(const int v) { return res[v]; } const std::vector<Edge>& to(const int v) const { return res[v]; } int size() const { return sz; } friend std::ostream& operator<<(std::ostream& os, const base_graph& g) { for (int i = 0; i < g.sz; i++) { for (const auto& e : g.es[i]) { os << e << '\n'; } } return os; } private: int sz; std::vector<std::vector<Edge>> es, res; }; template<typename Edge> using base_tree = base_graph<Edge>; using graph = base_graph<edge<>>; using tree = base_graph<edge<>>; template<typename Cost> using cost_graph = base_graph<edge<Cost>>; template<typename Cost> using cost_tree = base_graph<edge<Cost>>; template<typename Edge> std::vector<typename Edge::cost_type> dijkstra(const base_graph<Edge>& g, const int s) { using T = typename Edge::cost_type; std::vector<T> d(g.size(), inf_v<T>); using P = std::pair<T, int>; std::priority_queue<P, std::vector<P>, std::greater<P>> q; d[s] = 0, q.push({0, s}); while (not q.empty()) { const T cost = q.top().first; const int v = q.top().second; q.pop(); if (d[v] < cost) { continue; } for (const auto& e : g[v]) { const auto c = e.cost(); const int to = e.to(); if (d[to] <= d[v] + c) { continue; } d[to] = d[v] + c, q.push({d[to], to}); } } return d; } int main() { const auto [N, K] = in.tup<int, ll>(); const auto as = in.vec<ll>(N); const auto bs = in.vec<ll>(N); cost_graph<ll> g(2 * N); for (int i = 0; i < N; i++) { g.add_edge(i, i + N, as[i]); } for (int i = 0; i + 1 < N; i++) { g.add_edge(i + N, i + 1, bs[i + 1]); } for (int i = 0; i + 2 < N; i++) { g.add_edge(i + N, i + 2, bs[i + 2] + K); } const auto ts = dijkstra(g, 0); ll ans = 0; for (int i = 0; i < N; i++) { chmax(ans, ts[i]); } out.ln(ans); return 0; }