結果

問題 No.346 チワワ数え上げ問題
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-02-26 23:36:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 614 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 11,888 KB
実行使用メモリ 16,992 KB
最終ジャッジ日時 2023-10-24 09:51:31
合計ジャッジ時間 5,331 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 29 ms
9,976 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 30 ms
9,976 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 38 ms
10,716 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import itertools


def mykey(c):
    if c not in "cw":
        return "*"
    else:
        return c


def solve(s):
    answer = 0
    c_nums = []
    w_nums = []
    for k, g in itertools.groupby(s, mykey):
        if k == "c":
            c_nums.append(len("".join(g)))
        elif k == "w":
            if not c_nums:
                continue
            w_nums.append(len("".join(g)))
    for i, x in enumerate(c_nums):
        w = sum(w_nums[i:])
        answer += x * w * (w - 1) // 2
    return answer


if __name__ == '__main__':
    print(solve(input()))
0