結果
問題 | No.762 PDCAパス |
ユーザー | tenten |
提出日時 | 2022-08-03 09:51:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 395 ms / 2,000 ms |
コード長 | 2,796 bytes |
コンパイル時間 | 2,383 ms |
コンパイル使用メモリ | 78,724 KB |
実行使用メモリ | 65,580 KB |
最終ジャッジ日時 | 2024-09-12 22:36:06 |
合計ジャッジ時間 | 12,171 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,548 KB |
testcase_01 | AC | 56 ms
50,412 KB |
testcase_02 | AC | 55 ms
50,468 KB |
testcase_03 | AC | 56 ms
50,156 KB |
testcase_04 | AC | 56 ms
50,284 KB |
testcase_05 | AC | 55 ms
50,392 KB |
testcase_06 | AC | 55 ms
50,436 KB |
testcase_07 | AC | 56 ms
49,928 KB |
testcase_08 | AC | 55 ms
50,060 KB |
testcase_09 | AC | 56 ms
50,316 KB |
testcase_10 | AC | 56 ms
50,400 KB |
testcase_11 | AC | 56 ms
50,420 KB |
testcase_12 | AC | 57 ms
50,436 KB |
testcase_13 | AC | 55 ms
50,372 KB |
testcase_14 | AC | 55 ms
50,416 KB |
testcase_15 | AC | 56 ms
50,536 KB |
testcase_16 | AC | 56 ms
50,104 KB |
testcase_17 | AC | 55 ms
50,300 KB |
testcase_18 | AC | 56 ms
50,352 KB |
testcase_19 | AC | 55 ms
50,216 KB |
testcase_20 | AC | 56 ms
49,916 KB |
testcase_21 | AC | 57 ms
50,340 KB |
testcase_22 | AC | 261 ms
57,008 KB |
testcase_23 | AC | 263 ms
58,980 KB |
testcase_24 | AC | 383 ms
65,400 KB |
testcase_25 | AC | 395 ms
65,580 KB |
testcase_26 | AC | 288 ms
59,592 KB |
testcase_27 | AC | 291 ms
59,676 KB |
testcase_28 | AC | 384 ms
62,900 KB |
testcase_29 | AC | 379 ms
63,100 KB |
testcase_30 | AC | 365 ms
63,092 KB |
testcase_31 | AC | 374 ms
63,216 KB |
testcase_32 | AC | 378 ms
63,104 KB |
testcase_33 | AC | 347 ms
61,116 KB |
testcase_34 | AC | 339 ms
60,848 KB |
testcase_35 | AC | 348 ms
60,848 KB |
testcase_36 | AC | 303 ms
59,056 KB |
testcase_37 | AC | 298 ms
58,688 KB |
testcase_38 | AC | 301 ms
59,120 KB |
testcase_39 | AC | 296 ms
58,212 KB |
testcase_40 | AC | 299 ms
58,532 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); char[] types = sc.next().toCharArray(); ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int left = sc.nextInt() - 1; int right = sc.nextInt() - 1; if ((types[left] == 'P' && types[right] == 'D') || (types[left] == 'D' && types[right] == 'C') || (types[left] == 'C' && types[right] == 'A') ) { graph.get(left).add(right); } if ((types[left] == 'D' && types[right] == 'P') || (types[left] == 'C' && types[right] == 'D') || (types[left] == 'A' && types[right] == 'C') ) { graph.get(right).add(left); } } int[] counts = new int[n]; for (int i = 0; i < n; i++) { if (types[i] == 'A') { counts[i] = 1; } } for (int i = 0; i < n; i++) { if (types[i] == 'C') { for (int x : graph.get(i)) { counts[i] += counts[x]; counts[i] %= MOD; } } } for (int i = 0; i < n; i++) { if (types[i] == 'D') { for (int x : graph.get(i)) { counts[i] += counts[x]; counts[i] %= MOD; } } } int ans = 0; for (int i = 0; i < n; i++) { if (types[i] == 'P') { for (int x : graph.get(i)) { counts[i] += counts[x]; counts[i] %= MOD; } ans += counts[i]; ans %= MOD; } } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }