結果

問題 No.1702 count good string
コンテスト
ユーザー norioc
提出日時 2026-07-14 08:42:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 652 ms / 2,000 ms
+ 617µs
コード長 927 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 235 ms
コンパイル使用メモリ 95,724 KB
実行使用メモリ 86,428 KB
最終ジャッジ日時 2026-07-14 08:42:25
合計ジャッジ時間 17,376 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import pairwise


def accum_dp(xs: list, f, op, e, init: dict):
    dp = init.copy()
    for x in xs:
        pp = {}
        dp, pp = pp, dp
        for fm_key, fm_val in pp.items():
            for to_key, to_val in f(fm_key, fm_val, x):
                dp[to_key] = op(dp.get(to_key, e), to_val)

    return dp


def op(a, b):
    return (a + b) % MOD


def f(k, v, x):
    # k : (?の使用回数, 最後にマッチした文字)
    cnt, ch = k

    yield k, v  # 採用しない

    # 採用する
    for (a, b) in pairs:
        if (ch, x) == (a, b):
            yield (cnt, x), v

        if ch == a and x == '?' and cnt < 1:
            yield (cnt+1, b), v


MOD = 10**9 + 7
N = int(input())
S = input()

pairs = list(pairwise('^yukicoder'))
init = {(0, '^'): 1}
dp = accum_dp(S, f, op, 0, init)

ans = 0
for (_, ch), v in dp.items():
    if ch == 'r':
        ans += v
        ans %= MOD

print(ans)
0