結果
問題 | No.2889 Rusk |
ユーザー | tonegawa |
提出日時 | 2024-09-13 21:53:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 107 ms / 2,000 ms |
コード長 | 6,417 bytes |
コンパイル時間 | 1,436 ms |
コンパイル使用メモリ | 142,352 KB |
実行使用メモリ | 25,984 KB |
最終ジャッジ日時 | 2024-09-13 21:54:10 |
合計ジャッジ時間 | 5,764 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 6 ms
5,376 KB |
testcase_15 | AC | 18 ms
6,912 KB |
testcase_16 | AC | 44 ms
12,672 KB |
testcase_17 | AC | 13 ms
5,760 KB |
testcase_18 | AC | 37 ms
11,008 KB |
testcase_19 | AC | 71 ms
18,432 KB |
testcase_20 | AC | 87 ms
22,144 KB |
testcase_21 | AC | 71 ms
18,688 KB |
testcase_22 | AC | 61 ms
16,384 KB |
testcase_23 | AC | 48 ms
13,568 KB |
testcase_24 | AC | 85 ms
21,888 KB |
testcase_25 | AC | 48 ms
13,440 KB |
testcase_26 | AC | 70 ms
18,048 KB |
testcase_27 | AC | 88 ms
22,656 KB |
testcase_28 | AC | 53 ms
14,592 KB |
testcase_29 | AC | 55 ms
15,232 KB |
testcase_30 | AC | 55 ms
14,976 KB |
testcase_31 | AC | 88 ms
22,400 KB |
testcase_32 | AC | 39 ms
11,392 KB |
testcase_33 | AC | 12 ms
5,504 KB |
testcase_34 | AC | 105 ms
25,984 KB |
testcase_35 | AC | 104 ms
25,856 KB |
testcase_36 | AC | 104 ms
25,984 KB |
testcase_37 | AC | 103 ms
25,728 KB |
testcase_38 | AC | 103 ms
25,856 KB |
testcase_39 | AC | 62 ms
23,808 KB |
testcase_40 | AC | 48 ms
19,200 KB |
testcase_41 | AC | 65 ms
24,832 KB |
testcase_42 | AC | 45 ms
18,048 KB |
testcase_43 | AC | 22 ms
10,112 KB |
testcase_44 | AC | 58 ms
22,528 KB |
testcase_45 | AC | 44 ms
17,920 KB |
testcase_46 | AC | 13 ms
7,296 KB |
testcase_47 | AC | 24 ms
10,752 KB |
testcase_48 | AC | 52 ms
20,480 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 2 ms
5,376 KB |
testcase_54 | AC | 107 ms
25,856 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <array> #include <tuple> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <bitset> #include <cmath> #include <functional> #include <cassert> #include <climits> #include <iomanip> #include <numeric> #include <memory> #include <random> #include <thread> #include <chrono> #define allof(obj) (obj).begin(), (obj).end() #define range(i, l, r) for(int i=l;i<r;i++) #define unique_elem(obj) obj.erase(std::unique(allof(obj)), obj.end()) #define bit_subset(i, S) for(int i=S, zero_cnt=0;(zero_cnt+=i==S)<2;i=(i-1)&S) #define bit_kpop(i, n, k) for(int i=(1<<k)-1,x_bit,y_bit;i<(1<<n);x_bit=(i&-i),y_bit=i+x_bit,i=(!i?(1<<n):((i&~y_bit)/x_bit>>1)|y_bit)) #define bit_kth(i, k) ((i >> k)&1) #define bit_highest(i) (i?63-__builtin_clzll(i):-1) #define bit_lowest(i) (i?__builtin_ctzll(i):-1) #define sleepms(t) std::this_thread::sleep_for(std::chrono::milliseconds(t)) using ll = long long; using ld = long double; using ul = uint64_t; using pi = std::pair<int, int>; using pl = std::pair<ll, ll>; using namespace std; template<typename F, typename S> std::ostream &operator << (std::ostream &dest, const std::pair<F, S> &p) { dest << p.first << ' ' << p.second; return dest; } template<typename A, typename B> std::ostream &operator << (std::ostream &dest, const std::tuple<A, B> &t) { dest << std::get<0>(t) << ' ' << std::get<1>(t); return dest; } template<typename A, typename B, typename C> std::ostream &operator << (std::ostream &dest, const std::tuple<A, B, C> &t) { dest << std::get<0>(t) << ' ' << std::get<1>(t) << ' ' << std::get<2>(t); return dest; } template<typename A, typename B, typename C, typename D> std::ostream &operator << (std::ostream &dest, const std::tuple<A, B, C, D> &t) { dest << std::get<0>(t) << ' ' << std::get<1>(t) << ' ' << std::get<2>(t) << ' ' << std::get<3>(t); return dest; } template<typename T> std::ostream &operator << (std::ostream &dest, const std::vector<std::vector<T>> &v) { int sz = v.size(); if (!sz) return dest; for (int i = 0; i < sz; i++) { int m = v[i].size(); for (int j = 0; j < m; j++) dest << v[i][j] << (i != sz - 1 && j == m - 1 ? '\n' : ' '); } return dest; } template<typename T> std::ostream &operator << (std::ostream &dest, const std::vector<T> &v) { int sz = v.size(); if (!sz) return dest; for (int i = 0; i < sz - 1; i++) dest << v[i] << ' '; dest << v[sz - 1]; return dest; } template<typename T, size_t sz> std::ostream &operator << (std::ostream &dest, const std::array<T, sz> &v) { if (!sz) return dest; for (int i = 0; i < sz - 1; i++) dest << v[i] << ' '; dest << v[sz - 1]; return dest; } template<typename T> std::ostream &operator << (std::ostream &dest, const std::set<T> &v) { for (auto itr = v.begin(); itr != v.end();) { dest << *itr; itr++; if (itr != v.end()) dest << ' '; } return dest; } template<typename T, typename E> std::ostream &operator << (std::ostream &dest, const std::map<T, E> &v) { for (auto itr = v.begin(); itr != v.end(); ) { dest << '(' << itr->first << ", " << itr->second << ')'; itr++; if (itr != v.end()) dest << '\n'; } return dest; } template<typename T> vector<T> make_vec(size_t sz, T val) { return std::vector<T>(sz, val); } template<typename T, typename... Tail> auto make_vec(size_t sz, Tail ...tail) { return std::vector<decltype(make_vec<T>(tail...))>(sz, make_vec<T>(tail...)); } template<typename T> vector<T> read_vec(size_t sz) { std::vector<T> v(sz); for (int i = 0; i < (int)sz; i++) std::cin >> v[i]; return v; } template<typename T, typename... Tail> auto read_vec(size_t sz, Tail ...tail) { auto v = std::vector<decltype(read_vec<T>(tail...))>(sz); for (int i = 0; i < (int)sz; i++) v[i] = read_vec<T>(tail...); return v; } // x / y以上の最小の整数 ll ceil_div(ll x, ll y) { assert(y > 0); return (x + (x > 0 ? y - 1 : 0)) / y; } // x / y以下の最大の整数 ll floor_div(ll x, ll y) { assert(y > 0); return (x + (x > 0 ? 0 : -y + 1)) / y; } void io_init() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } int main() { io_init(); int N; std::cin >> N; auto A = read_vec<int>(N); auto B = read_vec<int>(N); auto C = read_vec<int>(N); auto dp = make_vec<ll>(N + 1, 9, -1LL); dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k <= 2; k++) { int idx = j * 3 + k; if (dp[i][idx] == -1) continue; // -2 if (j == 2) { dp[i + 1][2] = std::max(dp[i + 1][2], dp[i][idx] + A[i]); } // -1 if (j >= 1) { if (j == 2) { dp[i + 1][idx - 3] = std::max(dp[i + 1][idx - 3], dp[i][idx] + B[i]); } else { dp[i + 1][idx - 3] = std::max(dp[i + 1][idx - 3], dp[i][idx] + A[i]); } } // +0 { if (j == 2) { dp[i + 1][idx] = std::max(dp[i + 1][idx], dp[i][idx] + C[i]); } else if (j == 1) { dp[i + 1][idx] = std::max(dp[i + 1][idx], dp[i][idx] + B[i]); } else { dp[i + 1][idx] = std::max(dp[i + 1][idx], dp[i][idx] + A[i]); } } // +1 if (j <= 1 && k <= 1) { int I = (j + 1) * 3 + (k + 1); if (j == 0) { dp[i + 1][I] = std::max(dp[i + 1][I], dp[i][idx] + B[i]); } else if(j == 1) { dp[i + 1][I] = std::max(dp[i + 1][I], dp[i][idx] + C[i]); } } // +2 if (k == 0) { dp[i + 1][8] = std::max(dp[i + 1][8], dp[i][idx] + C[i]); } } } } ll ans = 0; for (int i = 0; i < 9; i++) { ans = std::max(ans, dp[N][i]); } std::cout << ans << '\n'; }