結果

問題 No.762 PDCAパス
ユーザー tentententen
提出日時 2023-02-16 08:29:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 2,758 bytes
コンパイル時間 3,593 ms
コンパイル使用メモリ 86,316 KB
実行使用メモリ 74,432 KB
最終ジャッジ日時 2023-09-25 14:06:20
合計ジャッジ時間 13,375 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,512 KB
testcase_01 AC 42 ms
49,364 KB
testcase_02 AC 43 ms
47,480 KB
testcase_03 AC 43 ms
49,492 KB
testcase_04 AC 42 ms
49,416 KB
testcase_05 AC 43 ms
49,432 KB
testcase_06 AC 42 ms
49,436 KB
testcase_07 AC 43 ms
49,604 KB
testcase_08 AC 43 ms
49,496 KB
testcase_09 AC 43 ms
49,440 KB
testcase_10 AC 42 ms
49,492 KB
testcase_11 AC 42 ms
49,396 KB
testcase_12 AC 43 ms
49,372 KB
testcase_13 AC 42 ms
49,388 KB
testcase_14 AC 42 ms
49,364 KB
testcase_15 AC 43 ms
49,548 KB
testcase_16 AC 45 ms
49,552 KB
testcase_17 AC 44 ms
49,448 KB
testcase_18 AC 43 ms
49,380 KB
testcase_19 AC 44 ms
49,368 KB
testcase_20 AC 44 ms
49,392 KB
testcase_21 AC 43 ms
49,664 KB
testcase_22 AC 272 ms
62,628 KB
testcase_23 AC 259 ms
60,440 KB
testcase_24 AC 386 ms
73,788 KB
testcase_25 AC 402 ms
73,824 KB
testcase_26 AC 284 ms
58,952 KB
testcase_27 AC 273 ms
61,220 KB
testcase_28 AC 442 ms
74,432 KB
testcase_29 AC 437 ms
74,108 KB
testcase_30 AC 434 ms
67,360 KB
testcase_31 AC 431 ms
67,068 KB
testcase_32 AC 421 ms
67,448 KB
testcase_33 AC 380 ms
65,156 KB
testcase_34 AC 372 ms
64,856 KB
testcase_35 AC 367 ms
65,024 KB
testcase_36 AC 323 ms
62,812 KB
testcase_37 AC 325 ms
62,804 KB
testcase_38 AC 327 ms
62,584 KB
testcase_39 AC 326 ms
63,340 KB
testcase_40 AC 343 ms
62,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0