結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-28 23:01:51 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,808 bytes |
| コンパイル時間 | 11,451 ms |
| コンパイル使用メモリ | 398,944 KB |
| 実行使用メモリ | 10,400 KB |
| 最終ジャッジ日時 | 2025-06-20 21:00:23 |
| 合計ジャッジ時間 | 14,691 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 14 TLE * 1 -- * 2 |
ソースコード
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 start in 0..n {
if s[start] == 'a' || s[start] == '?' {
dfs(
start,
0,
&mut ans,
question_count,
&mut vec![start],
&s,
&graph,
);
}
}
println!("{}", ans);
}
fn dfs(
pos: usize,
count: usize,
ans: &mut usize,
question_count: usize,
route: &mut Vec<usize>,
s: &Vec<char>,
graph: &Vec<Vec<usize>>,
) {
let target = match count {
0 => 'o',
1 => 'i',
_ => unreachable!(),
};
for &next in &graph[pos] {
if s[next] != target && s[next] != '?' {
continue;
}
if s[next] == '?' && route.contains(&next) {
continue;
}
route.push(next);
if count + 1 == 2 {
let rest_question_count =
question_count - route.iter().filter(|&&i| s[i] == '?').count();
*ans += pow(26, rest_question_count);
*ans %= 998244353;
continue;
}
dfs(next, count + 1, ans, question_count, route, s, graph);
route.pop();
}
}
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
}