結果
| 問題 | No.1702 count good string |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-07-16 04:01:28 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 695 ms / 2,000 ms |
| + 756µs | |
| コード長 | 907 bytes |
| 記録 | |
| コンパイル時間 | 239 ms |
| コンパイル使用メモリ | 95,704 KB |
| 実行使用メモリ | 87,108 KB |
| 最終ジャッジ日時 | 2026-07-16 04:01:50 |
| 合計ジャッジ時間 | 18,666 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
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, pc = k
yield k, v # 採用しない
# 採用する
for (a, b) in pairwise('^yukicoder'):
if (pc, x) == (a, b):
yield (cnt, x), v
if pc == a and x == '?' and cnt < 1:
yield (cnt+1, b), v
MOD = 10**9 + 7
N = int(input())
S = input()
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)
norioc