結果

問題 No.921 ずんだアロー
ユーザー qsako6qsako6
提出日時 2019-11-09 02:00:14
言語 Ruby
(3.3.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 11,516 KB
実行使用メモリ 26,392 KB
最終ジャッジ日時 2023-10-13 06:34:18
合計ジャッジ時間 4,097 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
15,268 KB
testcase_01 AC 67 ms
15,160 KB
testcase_02 AC 68 ms
15,068 KB
testcase_03 AC 68 ms
15,248 KB
testcase_04 AC 68 ms
15,128 KB
testcase_05 AC 71 ms
15,072 KB
testcase_06 AC 68 ms
15,168 KB
testcase_07 AC 70 ms
15,064 KB
testcase_08 AC 67 ms
15,168 KB
testcase_09 AC 67 ms
15,308 KB
testcase_10 AC 135 ms
21,024 KB
testcase_11 AC 145 ms
26,036 KB
testcase_12 AC 84 ms
16,684 KB
testcase_13 AC 122 ms
20,524 KB
testcase_14 AC 131 ms
20,688 KB
testcase_15 AC 106 ms
20,488 KB
testcase_16 AC 77 ms
15,464 KB
testcase_17 AC 137 ms
20,768 KB
testcase_18 AC 168 ms
26,376 KB
testcase_19 AC 167 ms
26,328 KB
testcase_20 AC 153 ms
26,392 KB
testcase_21 AC 151 ms
26,220 KB
testcase_22 AC 152 ms
26,376 KB
testcase_23 AC 148 ms
26,324 KB
testcase_24 AC 153 ms
26,236 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
a = gets.split.map(&:to_i)

dp = Array.new(n + 1) { Array.new(2, 0) }
# dp[i][j]:= i(i-indexed)番目までの餅を処理したうえでi番目の餅がずんだ餅(j = 1) / 餅(j = 0)である並びのうち、最適なものにおけるずんだ餅の数
n.times do |i|
  dp[i+1][0] = dp[i].max
  if i != 0 && a[i] != a[i-1]
    dp[i+1][1] = dp[i][0] + 1
  else
    dp[i+1][1] = dp[i].max + 1
  end
end
p dp[n].max
0