結果

問題 No.346 チワワ数え上げ問題
コンテスト
ユーザー はむ吉🐹
提出日時 2016-02-26 23:36:31
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 614 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 327 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 22,364 KB
最終ジャッジ日時 2026-04-11 07:52:40
合計ジャッジ時間 6,733 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 3 WA * 18 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/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