結果
| 問題 | No.3040 Aoiスコア |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-28 23:11:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 748 bytes |
| 記録 | |
| コンパイル時間 | 254 ms |
| コンパイル使用メモリ | 82,368 KB |
| 実行使用メモリ | 87,908 KB |
| 最終ジャッジ日時 | 2025-06-20 21:01:11 |
| 合計ジャッジ時間 | 8,165 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 TLE * 3 -- * 2 |
ソースコード
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":Q.append(((i,),0))
elif S[i]=="?":Q.append(((i,),1))
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,qcnt=Q.popleft()
for nxt in G[path[-1]]:
if nxt in set(path):continue
if S[nxt]==C[len(path)]:
if len(path)==2:
ans+=26**(Qcnt-qcnt)
else:Q.append((path+(nxt,),qcnt))
elif S[nxt]=="?":
if len(path)==2:
ans+=26**(Qcnt-(qcnt+1))
else:Q.append((path+(nxt,),qcnt+1))
print(ans%998244353)