結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー maguroflymagurofly
提出日時 2021-01-29 21:50:30
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 419 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 29,640 KB
最終ジャッジ日時 2023-09-09 15:13:10
合計ジャッジ時間 4,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,116 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 207 ms
29,444 KB
testcase_06 AC 206 ms
29,476 KB
testcase_07 AC 194 ms
29,504 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def evaluate(a, i)
    if a[i] != a[i+2] and (a[i] < a[i+1] and a[i+1] > a[i+2]) or (a[i] > a[i+1] and a[i+1] < a[i+2])
        a[i]
    else
        0
    end
end

T = gets.to_i
T.times do
    n = gets.to_i
    a = gets.split.map(&:to_i)
    a << a[0] << a[1]
    dp = [0, 0, 0]
    n.times do |i|
        value = evaluate(a, i)
        dp[i + 3] = [dp[i] + value, dp[i + 1], dp[i + 2]].max
    end
    puts dp[-1]
end
0