結果

問題 No.346 チワワ数え上げ問題
ユーザー wotsushiwotsushi
提出日時 2017-02-15 19:11:01
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 324 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-06-09 12:36:00
合計ジャッジ時間 3,516 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
12,288 KB
testcase_01 AC 74 ms
12,160 KB
testcase_02 AC 73 ms
12,288 KB
testcase_03 AC 74 ms
12,288 KB
testcase_04 AC 75 ms
12,160 KB
testcase_05 AC 75 ms
12,416 KB
testcase_06 AC 81 ms
12,160 KB
testcase_07 AC 74 ms
12,160 KB
testcase_08 AC 76 ms
12,160 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 79 ms
12,928 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 72 ms
12,160 KB
testcase_24 AC 74 ms
12,416 KB
testcase_25 AC 75 ms
12,288 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