結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー tonyu0tonyu0
提出日時 2021-04-24 20:21:58
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,098 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 29,292 KB
実行使用メモリ 5,020 KB
最終ジャッジ日時 2023-09-17 13:46:59
合計ジャッジ時間 1,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 12 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 28 ms
4,888 KB
testcase_07 AC 27 ms
4,992 KB
testcase_08 AC 28 ms
4,924 KB
testcase_09 AC 27 ms
4,940 KB
testcase_10 AC 26 ms
4,940 KB
testcase_11 AC 27 ms
4,940 KB
testcase_12 AC 26 ms
4,920 KB
testcase_13 AC 27 ms
5,000 KB
testcase_14 AC 27 ms
4,888 KB
testcase_15 AC 26 ms
4,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

long long n, a[200010], dp[200010];

int main(void) {
  int t;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld", &n);
    rep(i, 0, n) { scanf("%lld", &a[i]); }
    memcpy(a + n, a, 9);
    long long ans = 0;
    rep(o, 0, 3) {
      memset(dp, 0, n + 5);
      rep(i, 1, n + 1) dp[i] = -INF;
      rep(i, 0, n) {
        dp[i + 1] = max(dp[i + 1], dp[i]);
        if (i + 3 <= n &&
            (a[i + o] != a[i + 1 + o] && a[i + 1 + o] != a[i + 2 + o] &&
             a[i + 2 + o] != a[i + o]) &&
            ((a[i + o] > a[i + 1 + o] && a[i + 1 + o] < a[i + 2 + o]) ||
             (a[i + o] < a[i + 1 + o] && a[i + 1 + o] > a[i + 2 + o]))) {
          dp[i + 3] = max(dp[i + 3], dp[i] + a[i + o]);
        }
      }
      ans = max(ans, dp[n]);
    }
    printf("%lld\n", ans);
  }
}
0