結果

問題 No.762 PDCAパス
ユーザー tentententen
提出日時 2022-10-06 12:54:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 2,351 bytes
コンパイル時間 3,233 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 65,028 KB
最終ジャッジ日時 2023-08-30 23:37:31
合計ジャッジ時間 12,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,448 KB
testcase_01 AC 43 ms
49,288 KB
testcase_02 AC 42 ms
49,388 KB
testcase_03 AC 42 ms
49,292 KB
testcase_04 AC 43 ms
49,372 KB
testcase_05 AC 41 ms
49,292 KB
testcase_06 AC 42 ms
49,296 KB
testcase_07 AC 42 ms
49,284 KB
testcase_08 AC 42 ms
49,380 KB
testcase_09 AC 43 ms
49,616 KB
testcase_10 AC 42 ms
49,372 KB
testcase_11 AC 42 ms
49,296 KB
testcase_12 AC 42 ms
49,288 KB
testcase_13 AC 41 ms
49,372 KB
testcase_14 AC 41 ms
49,516 KB
testcase_15 AC 45 ms
49,380 KB
testcase_16 AC 44 ms
49,272 KB
testcase_17 AC 42 ms
47,348 KB
testcase_18 AC 43 ms
49,676 KB
testcase_19 AC 45 ms
49,372 KB
testcase_20 AC 43 ms
49,356 KB
testcase_21 AC 43 ms
49,388 KB
testcase_22 AC 240 ms
57,916 KB
testcase_23 AC 225 ms
56,104 KB
testcase_24 AC 308 ms
64,612 KB
testcase_25 AC 307 ms
65,028 KB
testcase_26 AC 232 ms
58,864 KB
testcase_27 AC 232 ms
58,676 KB
testcase_28 AC 325 ms
63,228 KB
testcase_29 AC 318 ms
62,924 KB
testcase_30 AC 305 ms
63,168 KB
testcase_31 AC 298 ms
62,780 KB
testcase_32 AC 307 ms
63,264 KB
testcase_33 AC 298 ms
60,612 KB
testcase_34 AC 296 ms
60,932 KB
testcase_35 AC 286 ms
60,452 KB
testcase_36 AC 262 ms
58,928 KB
testcase_37 AC 268 ms
58,116 KB
testcase_38 AC 267 ms
58,864 KB
testcase_39 AC 269 ms
58,108 KB
testcase_40 AC 269 ms
58,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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<>());
        }
        long[] pcounts = new long[n];
        long[] acounts = new long[n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            if (types[a] == 'D') {
                if (types[b] == 'P') {
                    pcounts[a]++;
                } else if (types[b] == 'C') {
                    graph.get(a).add(b);
                }
            } else if (types[a] == 'C') {
                if (types[b] == 'A') {
                    acounts[a]++;
                } else if (types[b] == 'D') {
                    graph.get(b).add(a);
                }
            } else if (types[a] == 'P') {
                if (types[b] == 'D') {
                    pcounts[b]++;
                }
            } else if (types[a] == 'A') {
                if (types[b] == 'C') {
                    acounts[b]++;
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int x : graph.get(i)) {
                ans += pcounts[i] * acounts[x];
                ans %= MOD;
            }
        }
        System.out.println(ans);
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0