結果

問題 No.762 PDCAパス
ユーザー htensaihtensai
提出日時 2019-12-30 09:40:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,029 ms / 2,000 ms
コード長 1,638 bytes
コンパイル時間 2,444 ms
コンパイル使用メモリ 77,748 KB
実行使用メモリ 55,572 KB
最終ジャッジ日時 2024-04-25 08:20:47
合計ジャッジ時間 25,365 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
41,284 KB
testcase_01 AC 132 ms
41,172 KB
testcase_02 AC 134 ms
41,208 KB
testcase_03 AC 132 ms
41,072 KB
testcase_04 AC 133 ms
41,136 KB
testcase_05 AC 134 ms
41,172 KB
testcase_06 AC 129 ms
41,036 KB
testcase_07 AC 133 ms
41,128 KB
testcase_08 AC 129 ms
41,192 KB
testcase_09 AC 136 ms
41,068 KB
testcase_10 AC 136 ms
41,444 KB
testcase_11 AC 134 ms
41,192 KB
testcase_12 AC 137 ms
41,224 KB
testcase_13 AC 137 ms
41,020 KB
testcase_14 AC 134 ms
41,340 KB
testcase_15 AC 142 ms
41,484 KB
testcase_16 AC 144 ms
41,348 KB
testcase_17 AC 141 ms
41,304 KB
testcase_18 AC 142 ms
41,584 KB
testcase_19 AC 141 ms
41,336 KB
testcase_20 AC 142 ms
41,452 KB
testcase_21 AC 126 ms
40,144 KB
testcase_22 AC 772 ms
51,892 KB
testcase_23 AC 804 ms
51,680 KB
testcase_24 AC 812 ms
55,520 KB
testcase_25 AC 846 ms
55,572 KB
testcase_26 AC 782 ms
52,984 KB
testcase_27 AC 824 ms
52,432 KB
testcase_28 AC 974 ms
54,772 KB
testcase_29 AC 937 ms
53,368 KB
testcase_30 AC 869 ms
55,236 KB
testcase_31 AC 969 ms
54,764 KB
testcase_32 AC 1,029 ms
55,560 KB
testcase_33 AC 995 ms
53,256 KB
testcase_34 AC 957 ms
55,184 KB
testcase_35 AC 1,023 ms
54,896 KB
testcase_36 AC 860 ms
52,044 KB
testcase_37 AC 1,002 ms
52,876 KB
testcase_38 AC 844 ms
53,720 KB
testcase_39 AC 977 ms
51,972 KB
testcase_40 AC 882 ms
51,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        long[] counts = new long[n];
        ArrayList<Integer>[] lists = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            if (arr[i] == 'D') {
                lists[i] = new ArrayList<Integer>();
            }
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            if (arr[a] == 'P') {
                if (arr[b] == 'D') {
                    counts[b]++;
                }
            } else if (arr[a] == 'D') {
                if (arr[b] == 'P') {
                    counts[a]++;
                } else if (arr[b] == 'C') {
                    lists[a].add(b);
                }
            } else if (arr[a] == 'C') {
                if (arr[b] == 'D') {
                    lists[b].add(a);
                } else if (arr[b] == 'A') {
                    counts[a]++;
                }
            } else if (arr[a] == 'A') {
                if (arr[b] == 'C') {
                    counts[b]++;
                }
            }
        }
        long total = 0;
        for (int i = 0; i < n; i++) {
            if (arr[i] != 'D') {
                continue;
            }
            for (int x : lists[i]) {
                total += counts[i] * counts[x];
                total %= MOD;
            }
        }
        System.out.println(total);
    }
}
0