結果
問題 | No.1702 count good string |
ユーザー |
![]() |
提出日時 | 2021-10-08 22:16:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 1,160 bytes |
コンパイル時間 | 456 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,416 KB |
最終ジャッジ日時 | 2024-07-23 04:44:46 |
合計ジャッジ時間 | 5,733 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 47 |
ソースコード
import syssys.setrecursionlimit(200005)int1 = lambda x: int(x)-1p2D = lambda x: print(*x, sep="\n")def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]inf = 10**19# md = 998244353md = 10**9+7from collections import defaultdictn = II()s = SI()def cnt(s, t):n = len(t)dp = [0]*(n+1)ctoi = defaultdict(list)for i, c in enumerate(t):ctoi[c].append(i)dp[0] = 1for c in s:for i in ctoi[c][::-1]:dp[i+1] += dp[i]dp[i+1] %= mdreturn dp[-1]t = "yukicoder"tt = [t]for i in range(len(t)):nt = t[:i]+"?"+t[i+1:]tt.append(nt)# print(tt)ans = 0for t in tt:ans += cnt(s, t)ans %= mdprint(ans)