結果
問題 |
No.3040 Aoiスコア
|
ユーザー |
|
提出日時 | 2025-02-28 22:31:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,079 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,704 KB |
実行使用メモリ | 85,244 KB |
最終ジャッジ日時 | 2025-06-20 20:59:12 |
合計ジャッジ時間 | 4,867 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 4 WA * 22 |
ソースコード
import sys sys.setrecursionlimit(10**8) from functools import cache n,m=map(int,input().split()) s=list(input()) connect=[[] for _ in range(n)] hate=s.count("?") for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 connect[a].append(b) connect[b].append(a) ans=0 mod=998244353 @cache def DFS(now,deepth,used): global ans global visited if deepth==2: cnt=1 for _ in range(hate-used): cnt*=26 cnt%=mod ans+=cnt ans%=mod return 0 for to in connect[now]: if s[to] == word[deepth+1] or s[to]=="?": if not visited[to]: visited[to]=True if s[to]=="?": DFS(to,deepth+1,used+1) else: DFS(to,deepth+1,used) visited[to]=False word=["a","o","i"] for start in range(n): visited=[False]*n if s[start] in {"a","?"}: visited[start]=True if s[start]=="?": DFS(start,0,1) else: DFS(start,0,0) ans%=mod print(ans)