結果

問題 No.346 チワワ数え上げ問題
ユーザー wotsushiwotsushi
提出日時 2017-02-15 19:11:01
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 324 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,492 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2023-08-28 17:25:52
合計ジャッジ時間 4,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,180 KB
testcase_01 AC 85 ms
15,048 KB
testcase_02 AC 83 ms
15,132 KB
testcase_03 AC 82 ms
15,224 KB
testcase_04 AC 85 ms
15,268 KB
testcase_05 AC 83 ms
15,084 KB
testcase_06 AC 86 ms
15,148 KB
testcase_07 AC 86 ms
15,112 KB
testcase_08 AC 85 ms
15,284 KB
testcase_09 AC 84 ms
15,196 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 87 ms
15,768 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 85 ms
15,056 KB
testcase_24 AC 83 ms
15,124 KB
testcase_25 AC 83 ms
15,112 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp
N = S.size
def f(i)
  @dp ||= {}
  @dp[i] ||= if i == N
               0
             elsif S[i] == 'w'
               1 + f(i + 1)
             else
               f(i + 1)
             end
end
ans = (0...N).map {|i|
  if S[i] == 'c'
    m = f(i)
    m * (m - 1) / 2
  else
    0
  end
}.inject(:+)
puts ans
0