結果

問題 No.762 PDCAパス
ユーザー tentententen
提出日時 2022-08-03 09:51:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 2,796 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 75,464 KB
実行使用メモリ 65,152 KB
最終ジャッジ日時 2023-10-10 00:09:44
合計ジャッジ時間 12,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,412 KB
testcase_01 AC 45 ms
47,680 KB
testcase_02 AC 45 ms
49,468 KB
testcase_03 AC 45 ms
49,284 KB
testcase_04 AC 45 ms
49,396 KB
testcase_05 AC 45 ms
49,456 KB
testcase_06 AC 44 ms
49,492 KB
testcase_07 AC 44 ms
47,676 KB
testcase_08 AC 43 ms
49,192 KB
testcase_09 AC 46 ms
49,204 KB
testcase_10 AC 44 ms
49,284 KB
testcase_11 AC 44 ms
49,316 KB
testcase_12 AC 46 ms
49,284 KB
testcase_13 AC 44 ms
49,520 KB
testcase_14 AC 44 ms
49,272 KB
testcase_15 AC 45 ms
47,308 KB
testcase_16 AC 46 ms
49,284 KB
testcase_17 AC 45 ms
49,276 KB
testcase_18 AC 44 ms
49,544 KB
testcase_19 AC 45 ms
49,208 KB
testcase_20 AC 45 ms
49,588 KB
testcase_21 AC 47 ms
49,920 KB
testcase_22 AC 244 ms
58,724 KB
testcase_23 AC 264 ms
58,452 KB
testcase_24 AC 372 ms
65,152 KB
testcase_25 AC 371 ms
65,096 KB
testcase_26 AC 283 ms
59,632 KB
testcase_27 AC 273 ms
59,364 KB
testcase_28 AC 369 ms
62,976 KB
testcase_29 AC 364 ms
62,916 KB
testcase_30 AC 348 ms
62,564 KB
testcase_31 AC 339 ms
62,832 KB
testcase_32 AC 352 ms
63,196 KB
testcase_33 AC 331 ms
60,528 KB
testcase_34 AC 329 ms
60,676 KB
testcase_35 AC 335 ms
60,444 KB
testcase_36 AC 291 ms
58,644 KB
testcase_37 AC 300 ms
58,796 KB
testcase_38 AC 286 ms
59,088 KB
testcase_39 AC 290 ms
58,952 KB
testcase_40 AC 299 ms
58,684 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<>());
        }
        for (int i = 0; i < m; i++) {
            int left = sc.nextInt() - 1;
            int right = sc.nextInt() - 1;
            if ((types[left] == 'P' && types[right] == 'D') ||
                (types[left] == 'D' && types[right] == 'C') ||
                (types[left] == 'C' && types[right] == 'A') ) {
                    graph.get(left).add(right);
            }
            if ((types[left] == 'D' && types[right] == 'P') ||
                (types[left] == 'C' && types[right] == 'D') ||
                (types[left] == 'A' && types[right] == 'C') ) {
                    graph.get(right).add(left);
            }
        }
        int[] counts = new int[n];
        for (int i = 0; i < n; i++) {
            if (types[i] == 'A') {
                counts[i] = 1;
            }
        }
        for (int i = 0; i < n; i++) {
            if (types[i] == 'C') {
                for (int x : graph.get(i)) {
                    counts[i] += counts[x];
                    counts[i] %= MOD;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (types[i] == 'D') {
                for (int x : graph.get(i)) {
                    counts[i] += counts[x];
                    counts[i] %= MOD;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (types[i] == 'P') {
                for (int x : graph.get(i)) {
                    counts[i] += counts[x];
                    counts[i] %= MOD;
                }
                ans += counts[i];
                ans %= MOD;
            }
        }
        System.out.println(ans);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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