結果
問題 |
No.3040 Aoiスコア
|
ユーザー |
|
提出日時 | 2025-02-28 23:09:00 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,970 bytes |
コンパイル時間 | 12,821 ms |
コンパイル使用メモリ | 385,324 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-20 21:01:03 |
合計ジャッジ時間 | 19,839 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 4 WA * 19 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 start in 0..n { if s[start] == 'a' { dfs( start, 0, &mut ans, question_count, &mut vec![false; n], &s, &graph, ); } else if s[start] == '?' { dfs( start, 0, &mut ans, question_count - 1, &mut vec![false; n], &s, &graph, ); } } println!("{}", ans); } fn dfs( pos: usize, count: usize, ans: &mut usize, question_count: usize, visited: &mut Vec<bool>, s: &Vec<char>, graph: &Vec<Vec<usize>>, ) { if count == 2 { *ans += pow(26, question_count); *ans %= 998244353; return; } let target = match count { 0 => 'o', 1 => 'i', _ => unreachable!(), }; for &next in &graph[pos] { if visited[next] { continue; } if s[next] == target { dfs(next, count + 1, ans, question_count, visited, s, graph); } else if s[next] == '?' { visited[next] = true; dfs(next, count + 1, ans, question_count - 1, visited, s, graph); visited[next] = false; } } } 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 }