結果

問題 No.2889 Rusk
ユーザー tnakao0123
提出日時 2024-09-15 15:10:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,726 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 42,496 KB
最終ジャッジ日時 2025-02-24 08:43:41
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~
main.cpp:36:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   for (int i = 0; i < n; i++) scanf("%d", bs + i);
      |                               ~~~~~^~~~~~~~~~~~~~
main.cpp:37:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   for (int i = 0; i < n; i++) scanf("%d", cs + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2889.cc:  No.2889 Rusk - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int M = 6;
enum { NY, SG1, DBL, SG0, SG2, FIN };

/* typedef */

using ll = long long;

/* global variables */

int as[MAX_N], bs[MAX_N], cs[MAX_N];
ll dp[MAX_N + 1][M];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);
  for (int i = 0; i < n; i++) scanf("%d", cs + i);

  for (int i = 0; i <= n; i++) fill(dp[i], dp[i] + M, -1);
  dp[0][NY] = 0;

  for (int i = 0; i < n; i++) {
    if (dp[i][NY] >= 0) {
      setmax(dp[i + 1][NY],  dp[i][NY] + as[i]);
      setmax(dp[i + 1][SG1], dp[i][NY] + bs[i]);
      setmax(dp[i + 1][DBL], dp[i][NY] + cs[i]);
    }
    if (dp[i][SG1] >= 0) {
      setmax(dp[i + 1][SG1], dp[i][SG1] + bs[i]);
      setmax(dp[i + 1][DBL], dp[i][SG1] + cs[i]);
      setmax(dp[i + 1][SG0], dp[i][SG1] + as[i]);
    }
    if (dp[i][DBL] >= 0) {
      setmax(dp[i + 1][DBL], dp[i][DBL] + cs[i]);
      setmax(dp[i + 1][SG2], dp[i][DBL] + bs[i]);
      setmax(dp[i + 1][FIN], dp[i][DBL] + as[i]);
    }
    if (dp[i][SG0] >= 0) {
      setmax(dp[i + 1][SG0], dp[i][SG0] + as[i]);
      setmax(dp[i + 1][SG2], dp[i][SG0] + bs[i]);
    }
    if (dp[i][SG2] >= 0) {
      setmax(dp[i + 1][SG2], dp[i][SG2] + bs[i]);
      setmax(dp[i + 1][FIN], dp[i][SG2] + as[i]);
    }
    if (dp[i][FIN] >= 0) {
      setmax(dp[i + 1][FIN], dp[i][FIN] + as[i]);
    }
  }

  ll maxd = *max_element(dp[n], dp[n] + M);
  printf("%lld\n", maxd);
  
  return 0;
}
0