結果

問題 No.1112 冥界の音楽
ユーザー ks2mks2m
提出日時 2020-07-10 23:12:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,659 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 77,492 KB
実行使用メモリ 40,816 KB
最終ジャッジ日時 2024-04-19 23:34:16
合計ジャッジ時間 6,646 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
39,276 KB
testcase_01 AC 54 ms
36,804 KB
testcase_02 AC 53 ms
36,492 KB
testcase_03 AC 55 ms
36,920 KB
testcase_04 AC 54 ms
37,028 KB
testcase_05 AC 55 ms
36,880 KB
testcase_06 AC 167 ms
40,556 KB
testcase_07 AC 55 ms
36,728 KB
testcase_08 AC 57 ms
36,836 KB
testcase_09 AC 121 ms
39,016 KB
testcase_10 AC 54 ms
36,880 KB
testcase_11 AC 123 ms
39,088 KB
testcase_12 AC 56 ms
36,840 KB
testcase_13 AC 166 ms
40,732 KB
testcase_14 AC 164 ms
40,816 KB
testcase_15 AC 122 ms
39,188 KB
testcase_16 AC 54 ms
36,752 KB
testcase_17 AC 124 ms
39,136 KB
testcase_18 AC 121 ms
39,060 KB
testcase_19 AC 54 ms
36,844 KB
testcase_20 AC 73 ms
37,824 KB
testcase_21 AC 157 ms
40,696 KB
testcase_22 AC 159 ms
40,664 KB
testcase_23 AC 126 ms
39,340 KB
testcase_24 AC 52 ms
36,820 KB
testcase_25 AC 50 ms
36,740 KB
testcase_26 AC 48 ms
36,844 KB
testcase_27 AC 53 ms
36,656 KB
testcase_28 AC 57 ms
36,780 KB
testcase_29 AC 49 ms
36,948 KB
testcase_30 AC 116 ms
38,940 KB
testcase_31 AC 54 ms
37,016 KB
testcase_32 AC 120 ms
38,964 KB
testcase_33 AC 54 ms
36,652 KB
testcase_34 AC 53 ms
36,900 KB
testcase_35 AC 53 ms
36,944 KB
testcase_36 AC 163 ms
40,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int k = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		long n = Long.parseLong(sa[2]);
		int max = 62;
		int k2 = k * k;
		long[][][] g = new long[max][k2][k2];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int p = Integer.parseInt(sa[0]) - 1;
			int q = Integer.parseInt(sa[1]) - 1;
			int r = Integer.parseInt(sa[2]) - 1;
			int pq = p * k + q;
			int qr = q * k + r;
			g[0][pq][qr] = 1;
		}
		br.close();

		int mod = 1000000007;
		for (int i = 0; i < max - 1; i++) {
//			for (int j = 0; j < k2; j++) {
//				for (int j2 = 0; j2 < k2; j2++) {
//					System.out.print(g[i][j][j2] + "\t");
//				}
//				System.out.println();
//			}
//			System.out.println();
			for (int j = 0; j < k2; j++) {
				for (int j2 = 0; j2 < k2; j2++) {
					for (int x = 0; x < k2; x++) {
						g[i + 1][j][j2] += g[i][j][x] * g[i][x][j2];
						g[i + 1][j][j2] %= mod;
					}
				}
			}
		}

		long n2 = n - 2;
		long[] dp = new long[k2];
		for (int i = 0; i < k; i++) {
			dp[i] = 1;
		}
		for (int i = 0; i < max - 1; i++) {
			if ((n2 >> i & 1) == 1) {
				long[] work = new long[k2];
				for (int j = 0; j < k2; j++) {
					for (int x = 0; x < k2; x++) {
						work[j] += dp[x] * g[i][x][j];
						work[j] %= mod;
					}
				}
				dp = work;
			}
		}

		long ans = 0;
		for (int i = 0; i < k2; i+=k) {
			ans += dp[i];
		}
		ans %= mod;
		System.out.println(ans);
	}
}
0