結果
問題 |
No.762 PDCAパス
|
ユーザー |
![]() |
提出日時 | 2020-09-01 15:18:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,261 ms / 2,000 ms |
コード長 | 1,513 bytes |
コンパイル時間 | 2,594 ms |
コンパイル使用メモリ | 78,828 KB |
実行使用メモリ | 80,272 KB |
最終ジャッジ日時 | 2024-11-19 03:08:24 |
合計ジャッジ時間 | 27,526 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); char[] arr = 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 a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } int[] pCounts = new int[n]; for (int i = 0; i < n; i++) { if (arr[i] == 'P') { pCounts[i]++; } } int[] dCounts = new int[n]; for (int i = 0; i < n; i++) { if (arr[i] != 'D') { continue; } for (int x : graph.get(i)) { dCounts[i] += pCounts[x]; dCounts[i] %= MOD; } } int[] cCounts = new int[n]; for (int i = 0; i < n; i++) { if (arr[i] != 'C') { continue; } for (int x : graph.get(i)) { cCounts[i] += dCounts[x]; cCounts[i] %= MOD; } } int total = 0; for (int i = 0; i < n; i++) { if (arr[i] != 'A') { continue; } for (int x : graph.get(i)) { total += cCounts[x]; total %= MOD; } } System.out.println(total); } }