結果

問題 No.762 PDCAパス
ユーザー YamaKasaYamaKasa
提出日時 2019-02-12 17:47:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 841 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 74,580 KB
実行使用メモリ 66,472 KB
最終ジャッジ日時 2023-10-11 10:57:08
合計ジャッジ時間 22,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,372 KB
testcase_01 AC 121 ms
56,172 KB
testcase_02 AC 124 ms
55,716 KB
testcase_03 AC 120 ms
55,832 KB
testcase_04 AC 121 ms
55,844 KB
testcase_05 AC 120 ms
56,164 KB
testcase_06 AC 120 ms
55,736 KB
testcase_07 AC 122 ms
56,104 KB
testcase_08 AC 121 ms
55,668 KB
testcase_09 AC 121 ms
56,124 KB
testcase_10 AC 122 ms
55,976 KB
testcase_11 AC 123 ms
56,040 KB
testcase_12 AC 124 ms
55,820 KB
testcase_13 AC 121 ms
56,060 KB
testcase_14 AC 120 ms
56,356 KB
testcase_15 AC 130 ms
55,952 KB
testcase_16 AC 137 ms
56,136 KB
testcase_17 AC 127 ms
56,264 KB
testcase_18 AC 129 ms
55,936 KB
testcase_19 AC 126 ms
55,728 KB
testcase_20 AC 126 ms
56,212 KB
testcase_21 AC 128 ms
55,952 KB
testcase_22 AC 677 ms
63,836 KB
testcase_23 AC 687 ms
64,792 KB
testcase_24 AC 721 ms
64,808 KB
testcase_25 AC 760 ms
63,844 KB
testcase_26 AC 676 ms
64,524 KB
testcase_27 AC 676 ms
64,968 KB
testcase_28 AC 825 ms
66,116 KB
testcase_29 AC 841 ms
65,908 KB
testcase_30 AC 816 ms
66,000 KB
testcase_31 AC 819 ms
66,032 KB
testcase_32 AC 807 ms
66,352 KB
testcase_33 AC 787 ms
66,228 KB
testcase_34 AC 787 ms
66,224 KB
testcase_35 AC 766 ms
66,268 KB
testcase_36 AC 716 ms
66,020 KB
testcase_37 AC 722 ms
66,472 KB
testcase_38 AC 729 ms
66,384 KB
testcase_39 AC 732 ms
66,424 KB
testcase_40 AC 744 ms
65,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		String S = sc.next();
		int[] u = new int[M];
		int[] v = new int[M];
		for(int i = 0; i < M; i++) {
			u[i] = sc.nextInt() - 1;
			v[i] = sc.nextInt() - 1;
		}
		sc.close();
		long mod = (long)Math.pow(10, 9) + 7;
		int cp = 0;
		int cd = 0;
		int cc = 0;
		int ca = 0;
		int[] node = new int[N];
		for(int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if(c == 'P') {
				node[i] = cp;
				cp++;
			}else if(c == 'D') {
				node[i] = cd;
				cd++;
			}else if(c == 'C') {
				node[i] = cc;
				cc++;
			}else if(c == 'A') {
				node[i] = ca;
				ca++;
			}
		}
		if(cp == 0 || cd == 0 || cc == 0 || ca == 0) {
			System.out.println(0);
			System.exit(0);
		}
		long[] C = new long[cc];
		for(int i = 0; i < M; i++) {
			char cu = S.charAt(u[i]);
			char cv = S.charAt(v[i]);
			if(cu == 'C' && cv == 'A') {
				C[node[u[i]]]++;
			}else if(cu == 'A' && cv == 'C'){
				C[node[v[i]]]++;
			}
		}
		long[] D = new long[cd];
		for(int i = 0; i < M; i++) {
			char cu = S.charAt(u[i]);
			char cv = S.charAt(v[i]);
			if(cu == 'D' && cv == 'C') {
				D[node[u[i]]] += C[node[v[i]]];
				D[node[u[i]]] %= mod;
			}else if(cu == 'C' && cv == 'D'){
				D[node[v[i]]] += C[node[u[i]]];
				D[node[v[i]]] %= mod;
			}
		}
		long[] P = new long[cp];
		for(int i = 0; i < M; i++) {
			char cu = S.charAt(u[i]);
			char cv = S.charAt(v[i]);
			if(cu == 'P' && cv == 'D') {
				P[node[u[i]]] += D[node[v[i]]];
				P[node[u[i]]] %= mod;
			}else if(cu == 'D' && cv == 'P'){
				P[node[v[i]]] += D[node[u[i]]];
				P[node[v[i]]] %= mod;
			}
		}
		long ans = 0;
		for(long i : P) {
			ans += i;
			ans %= mod;
		}
		System.out.println(ans);
	}
}
0