結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー yuruhiyayuruhiya
提出日時 2021-01-29 22:59:32
言語 Crystal
(1.11.2)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 18,349 ms
コンパイル使用メモリ 257,764 KB
実行使用メモリ 26,380 KB
最終ジャッジ日時 2023-09-13 13:25:59
合計ジャッジ時間 21,579 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,492 KB
testcase_02 AC 73 ms
5,060 KB
testcase_03 AC 16 ms
5,056 KB
testcase_04 AC 28 ms
5,092 KB
testcase_05 AC 98 ms
26,380 KB
testcase_06 AC 99 ms
26,300 KB
testcase_07 AC 88 ms
26,356 KB
testcase_08 AC 103 ms
26,356 KB
testcase_09 AC 104 ms
20,760 KB
testcase_10 AC 104 ms
20,864 KB
testcase_11 AC 103 ms
20,844 KB
testcase_12 AC 102 ms
20,744 KB
testcase_13 AC 103 ms
20,744 KB
testcase_14 AC 102 ms
20,840 KB
testcase_15 AC 101 ms
20,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def check(a)
  a.uniq.size == 3 && (a.max == a[1] || a.min == a[1])
end

def func(n, a)
  dp = [0i64] * -~n
  (0..n).each do |i|
    dp[i] = {dp[i], dp[i - 1] || 0i64}.max
    dp[i + 3] = {dp[i + 3], dp[i] + a[i]}.max if check(a[i, 3])
  end
  dp[n]
end

read_line.to_i.times do
  n = read_line.to_i
  a = read_line.split.map(&.to_i64)
  puts [func(n, a), func(n, a[1..] + a[0, 1]), func(n, a[2..] + a[0, 2])].max
end
0