結果
問題 | No.762 PDCAパス |
ユーザー | tenten |
提出日時 | 2023-02-16 08:29:52 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 2,758 bytes |
コンパイル時間 | 2,368 ms |
コンパイル使用メモリ | 92,732 KB |
実行使用メモリ | 73,316 KB |
最終ジャッジ日時 | 2024-07-18 11:05:46 |
合計ジャッジ時間 | 11,367 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
50,392 KB |
testcase_01 | AC | 50 ms
50,328 KB |
testcase_02 | AC | 51 ms
50,316 KB |
testcase_03 | AC | 51 ms
50,428 KB |
testcase_04 | AC | 51 ms
50,468 KB |
testcase_05 | AC | 49 ms
49,996 KB |
testcase_06 | AC | 49 ms
50,304 KB |
testcase_07 | AC | 50 ms
50,468 KB |
testcase_08 | AC | 51 ms
50,396 KB |
testcase_09 | AC | 50 ms
50,020 KB |
testcase_10 | AC | 50 ms
50,352 KB |
testcase_11 | AC | 52 ms
50,024 KB |
testcase_12 | AC | 50 ms
50,556 KB |
testcase_13 | AC | 48 ms
50,384 KB |
testcase_14 | AC | 50 ms
50,456 KB |
testcase_15 | AC | 50 ms
50,292 KB |
testcase_16 | AC | 54 ms
50,448 KB |
testcase_17 | AC | 50 ms
50,228 KB |
testcase_18 | AC | 53 ms
50,512 KB |
testcase_19 | AC | 52 ms
50,372 KB |
testcase_20 | AC | 52 ms
50,108 KB |
testcase_21 | AC | 52 ms
50,152 KB |
testcase_22 | AC | 274 ms
59,860 KB |
testcase_23 | AC | 254 ms
61,348 KB |
testcase_24 | AC | 354 ms
73,280 KB |
testcase_25 | AC | 372 ms
73,316 KB |
testcase_26 | AC | 271 ms
61,572 KB |
testcase_27 | AC | 262 ms
62,212 KB |
testcase_28 | AC | 433 ms
72,720 KB |
testcase_29 | AC | 422 ms
72,532 KB |
testcase_30 | AC | 392 ms
66,392 KB |
testcase_31 | AC | 399 ms
66,264 KB |
testcase_32 | AC | 385 ms
66,576 KB |
testcase_33 | AC | 350 ms
64,988 KB |
testcase_34 | AC | 353 ms
65,240 KB |
testcase_35 | AC | 349 ms
65,160 KB |
testcase_36 | AC | 317 ms
63,220 KB |
testcase_37 | AC | 304 ms
62,900 KB |
testcase_38 | AC | 306 ms
63,008 KB |
testcase_39 | AC | 330 ms
63,176 KB |
testcase_40 | AC | 310 ms
63,000 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; 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 a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } long[] pCounts = new long[n]; long[] aCounts = new long[n]; for (int i = 0; i < n; i++) { if (types[i] == 'D') { for (int x : graph.get(i)) { if (types[x] == 'P') { pCounts[i]++; } } } else if (types[i] == 'C') { for (int x : graph.get(i)) { if (types[x] == 'A') { aCounts[i]++; } } } } long ans = 0; for (int i = 0; i < n; i++) { if (types[i] == 'D') { for (int x : graph.get(i)) { ans += pCounts[i] * aCounts[x] % MOD; ans %= MOD; } } } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }