結果

問題 No.346 チワワ数え上げ問題
ユーザー はむ吉🐹
提出日時 2016-02-26 23:36:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 614 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 19,104 KB
最終ジャッジ日時 2024-09-23 02:24:21
合計ジャッジ時間 5,168 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 3 WA * 18 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

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