結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-01 08:18:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 1,000 ms |
| コード長 | 807 bytes |
| コンパイル時間 | 199 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 77,576 KB |
| 最終ジャッジ日時 | 2025-06-20 21:02:20 |
| 合計ジャッジ時間 | 2,636 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
N, M = map(int, input().split())
S = input()
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)
mod = 998244353
q = S.count("?")
mypow = [1]
for _ in range(q):
mypow.append(mypow[-1] * 26 % mod)
ans = 0
for i in range(N):
if S[i] != "o" and S[i] != "?": continue
pp = q - (S[i] == "?")
ac = 0
ic = 0
xc = 0
for j in G[i]:
if S[j] == "a":
ac += 1
elif S[j] == "i":
ic += 1
elif S[j] == "?":
xc += 1
ans += ac * ic * mypow[pp] % mod
if xc > 0:
ans += ac * xc * mypow[pp-1] % mod
ans += xc * ic * mypow[pp-1] % mod
if xc > 1:
ans += xc * (xc-1) * mypow[pp-2] % mod
ans %= mod
print(ans)