結果

問題 No.3040 Aoiスコア
ユーザー tkykwtnb
提出日時 2025-02-28 23:04:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 646 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 118,340 KB
最終ジャッジ日時 2025-06-20 21:00:47
合計ジャッジ時間 8,671 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 10 TLE * 3 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,M=map(int,input().split())
S=input()
C="aoi"
Qcnt=S.count("?")
Q=[]
for i in range(N):
    if S[i]=="a" or S[i]=="?":Q.append(((i,),[S[i]]))
G=[[] for _ in range(N)]
for _ in range(M):
    A,B=map(int,input().split())
    A-=1;B-=1
    G[A].append(B)
    G[B].append(A)
Q=deque(Q)
ans=0
while Q:
    path,str=Q.popleft()
    for nxt in G[path[-1]]:
        if nxt in path:continue
        if S[nxt]==C[len(path)] or S[nxt]=="?":
            if len(path)==2:
                str.append(S[nxt])
                ans+=26**(Qcnt-str.count("?"))
            else:Q.append((path+(nxt,),str+[S[nxt]]))
print(ans%998244353)
0