結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-01 07:21:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 689 ms / 1,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 81,944 KB |
| 実行使用メモリ | 79,420 KB |
| 最終ジャッジ日時 | 2025-06-20 21:02:20 |
| 合計ジャッジ時間 | 5,273 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
import sys
sys.setrecursionlimit(10**8)
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
def DFS(now,deepth,used):
global ans
global visited
if deepth==2:
cnt=tw[hate-used]
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="aoi"
tw=[1]
for i in range(7000):
tw.append((tw[-1]*26)%mod)
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)