結果
問題 | No.2889 Rusk |
ユーザー |
|
提出日時 | 2024-09-13 21:36:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,965 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 201,708 KB |
最終ジャッジ日時 | 2025-02-24 07:15:28 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define ll long long#define pii pair<int, int>#define pll pair<ll, ll>#define vi vector<int>#define vl vector<ll>#define ov4(a, b, c, d, name, ...) name#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))#define rep2(i, a, b) rep3(i, a, b, 1)#define rep1(i, n) rep2(i, 0, n)#define rep0(n) rep1(aaaaa, n)#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)#define per(i, a, b) for(ll i = (a) - 1; i >= (b); i--)#define fore(e, v) for(auto &&e : v)#define all(a) begin(a), end(a)#define si(a) (int)(size(a))#define lb(v, x) (lower_bound(all(v), x) - begin(v))#define eb emplace_backtemplate <typename T, typename S> bool chmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; }template <typename T, typename S> bool chmax(T &a, const S &b) { return a < b ? a = b, 1 : 0; }const int INF = 1e9 + 100;const ll INFL = 3e18 + 100;#define i128 __int128_tstruct _ {_() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }} __;int main() {int n;cin >> n;vl a(n), b(n), c(n);fore(e, a) cin >> e;fore(e, b) cin >> e;fore(e, c) cin >> e;ll ma = 0;// 0 (1 or 2) 0vector<vl> dp(n + 1, vl(5, -INFL));vi v{0, 1, 2, 1, 0};rep(j, 5) dp[0][j] = 0;rep(i, n) {ll now = dp[i][0] + a[i];chmax(dp[i + 1][0], now);rep(j, 1, 5) {chmax(now, dp[i][j] + (v[j] == 0 ? a[i] : v[j] == 1 ? b[i] : c[i]));chmax(dp[i + 1][j], now);}}chmax(ma, *max_element(all(dp[n])));// 0 1 0 1 0dp = vector<vl>(n + 1, vl(5, -INFL));rep(j, 5) dp[0][j] = 0;rep(i, n) {chmax(dp[i + 1][0], dp[i][0] + a[i]);rep(j, 1, 5) {chmax(dp[i + 1][j], dp[i][j - 1] + (j & 1 ? a[i] : b[i]));chmax(dp[i + 1][j], dp[i][j] + (~j & 1 ? a[i] : b[i]));}}chmax(ma, *max_element(all(dp[n])));cout << ma << endl;}