結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー yuruhiyayuruhiya
提出日時 2021-01-29 23:00:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 11,188 KB
実行使用メモリ 41,880 KB
最終ジャッジ日時 2023-09-09 16:44:20
合計ジャッジ時間 7,975 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,040 KB
testcase_01 AC 83 ms
15,296 KB
testcase_02 AC 347 ms
15,320 KB
testcase_03 AC 136 ms
15,344 KB
testcase_04 AC 185 ms
15,404 KB
testcase_05 AC 537 ms
41,880 KB
testcase_06 AC 537 ms
41,604 KB
testcase_07 AC 433 ms
41,816 KB
testcase_08 AC 550 ms
41,832 KB
testcase_09 AC 509 ms
41,064 KB
testcase_10 AC 511 ms
40,916 KB
testcase_11 AC 517 ms
40,840 KB
testcase_12 AC 517 ms
40,828 KB
testcase_13 AC 517 ms
40,964 KB
testcase_14 AC 514 ms
41,124 KB
testcase_15 AC 512 ms
41,148 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

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

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