結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-28 23:43:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,488 bytes |
| コンパイル時間 | 13,014 ms |
| コンパイル使用メモリ | 401,572 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 21:01:54 |
| 合計ジャッジ時間 | 19,697 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 TLE * 3 |
ソースコード
use proconio::{
input,
marker::{Chars, Usize1},
};
fn main() {
input! {
n: usize,
m: usize,
s: Chars,
ab: [(Usize1, Usize1); m],
}
let mut graph = vec![vec![]; n];
for (a, b) in ab {
graph[a].push(b);
graph[b].push(a);
}
let question_count = s.iter().filter(|&&x| x == '?').count();
let mut ans = 0;
for center in 0..n {
let question_count = match s[center] {
'o' => question_count,
'?' => question_count - 1,
_ => continue,
};
for &head in &graph[center] {
let question_count = match s[head] {
'a' => question_count,
'?' => question_count - 1,
_ => continue,
};
for &tail in &graph[center] {
if head == tail {
continue;
}
let question_count = match s[tail] {
'i' => question_count,
'?' => question_count - 1,
_ => continue,
};
ans += pow(26, question_count);
ans %= 998244353;
}
}
}
println!("{}", ans);
}
fn pow(mut n: usize, mut m: usize) -> usize {
let mut r = 1;
while m > 0 {
if m & 1 == 1 {
r *= n;
r %= 998244353;
}
n *= n;
n %= 998244353;
m >>= 1;
}
r
}