結果

問題 No.346 チワワ数え上げ問題
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-02-19 14:33:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 397 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 14,088 KB
最終ジャッジ日時 2023-10-23 18:26:37
合計ジャッジ時間 2,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,016 KB
testcase_01 AC 27 ms
10,016 KB
testcase_02 AC 28 ms
10,016 KB
testcase_03 AC 28 ms
10,016 KB
testcase_04 AC 28 ms
10,016 KB
testcase_05 AC 28 ms
10,016 KB
testcase_06 AC 29 ms
10,016 KB
testcase_07 AC 28 ms
10,016 KB
testcase_08 AC 28 ms
10,016 KB
testcase_09 AC 31 ms
10,016 KB
testcase_10 AC 75 ms
13,824 KB
testcase_11 AC 59 ms
12,248 KB
testcase_12 AC 67 ms
13,060 KB
testcase_13 AC 53 ms
11,916 KB
testcase_14 AC 29 ms
10,048 KB
testcase_15 AC 63 ms
12,504 KB
testcase_16 AC 68 ms
13,220 KB
testcase_17 AC 75 ms
13,824 KB
testcase_18 AC 76 ms
13,824 KB
testcase_19 AC 67 ms
13,228 KB
testcase_20 AC 96 ms
10,920 KB
testcase_21 AC 92 ms
14,088 KB
testcase_22 AC 94 ms
14,088 KB
testcase_23 AC 28 ms
10,016 KB
testcase_24 AC 29 ms
10,016 KB
testcase_25 AC 29 ms
10,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

### 文字列全体に含まれるチワワ列の総数を求める ###

def nC2(n):
    return n * (n - 1) // 2

S = input()
N = len(S)

# w[i] = 区間[i, N]に含まれる'w'の個数
w = [0] * (N + 1)
for i in range(N)[::-1]:
    w[i] += w[i+1]
    if S[i] == 'w':
        w[i] += 1

sm = 0
for i in range(N-1):
    if S[i] == 'c':
        sm += nC2(w[i+1])
print(sm)
0