結果
問題 |
No.3040 Aoiスコア
|
ユーザー |
![]() |
提出日時 | 2025-03-04 09:22:19 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 431 ms / 1,000 ms |
コード長 | 2,785 bytes |
コンパイル時間 | 2,839 ms |
コンパイル使用メモリ | 81,420 KB |
実行使用メモリ | 50,076 KB |
最終ジャッジ日時 | 2025-06-20 21:03:11 |
合計ジャッジ時間 | 7,106 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); char[] edges = sc.next().toCharArray(); List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } int totalQ = 0; for (char c : edges) { if (c == '?') { totalQ++; } } long[] powers = new long[totalQ + 1]; powers[0] = 1; for (int i = 1; i <= totalQ; i++) { powers[i] = powers[i - 1] * 26 % MOD; } long ans = 0; for (int i = 0; i < n; i++) { int addO = 0; if (edges[i] == '?') { addO = 1; } else if (edges[i] != 'o') { continue; } for (int x : graph.get(i)) { int addA = 0; if (edges[x] == '?') { addA = 1; } else if (edges[x] != 'a') { continue; } for (int y : graph.get(i)) { int addI = 0; if (x == y) { continue; } else if (edges[y] == '?') { addI++; } else if (edges[y] != 'i') { continue; } ans += powers[totalQ - addO - addA - addI]; ans %= MOD; } } } System.out.println(ans); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }