結果

問題 No.1050 Zero (Maximum)
ユーザー htensaihtensai
提出日時 2020-06-04 17:47:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 4,204 ms
コンパイル使用メモリ 73,172 KB
実行使用メモリ 56,580 KB
最終ジャッジ日時 2023-08-19 20:35:50
合計ジャッジ時間 8,284 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,880 KB
testcase_01 AC 128 ms
55,636 KB
testcase_02 AC 182 ms
56,304 KB
testcase_03 AC 164 ms
56,168 KB
testcase_04 AC 180 ms
56,188 KB
testcase_05 AC 199 ms
56,088 KB
testcase_06 AC 172 ms
56,156 KB
testcase_07 AC 171 ms
56,148 KB
testcase_08 AC 135 ms
55,980 KB
testcase_09 AC 164 ms
56,580 KB
testcase_10 AC 188 ms
56,104 KB
testcase_11 AC 199 ms
56,288 KB
testcase_12 AC 133 ms
53,832 KB
testcase_13 AC 128 ms
55,732 KB
testcase_14 AC 130 ms
55,720 KB
testcase_15 AC 138 ms
55,764 KB
testcase_16 AC 195 ms
56,320 KB
testcase_17 AC 183 ms
56,352 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 m = sc.nextInt();
		int kk = sc.nextInt();
		long[][][] dp = new long[m][m][31];
		for (int i = 0; i < m; i++) {
		    for (int j = 0; j < m; j++) {
		        dp[i][(i + j) % m][0]++;
		        dp[i][i * j % m][0]++;
		    }
		}
		for (int i = 1; i < 31; i++) {
		    for (int j = 0; j < m; j++) {
		        for (int k = 0; k < m; k++) {
		            for (int l = 0; l < m; l++) {
		                dp[j][l][i] += dp[j][k][i - 1] * dp[k][l][i - 1] % MOD;
		                dp[j][l][i] %= MOD;
		            }
		        }
		    }
		}
		long[] base = new long[m];
		base[0] = 1;
		for (int i = 30; i >= 0 && kk > 0; i--) {
		    if (kk < (1 << i)) {
		        continue;
		    }
		    kk -= (1 << i);
		    long[] next = new long[m];
		    for (int j = 0; j < m; j++) {
		        for (int k = 0; k < m; k++) {
		            next[k] += base[j] * dp[j][k][i] % MOD;
		            next[k] %= MOD;
		        }
		    }
		    base = next;
		}
		System.out.println(base[0]);
	}
}
0