結果
問題 | No.1050 Zero (Maximum) |
ユーザー | silviasetitech |
提出日時 | 2020-05-10 10:29:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 248 ms / 2,000 ms |
コード長 | 3,044 bytes |
コンパイル時間 | 1,786 ms |
コンパイル使用メモリ | 79,332 KB |
実行使用メモリ | 58,072 KB |
最終ジャッジ日時 | 2024-07-07 06:12:07 |
合計ジャッジ時間 | 5,319 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
52,712 KB |
testcase_01 | AC | 108 ms
53,728 KB |
testcase_02 | AC | 152 ms
53,780 KB |
testcase_03 | AC | 151 ms
54,060 KB |
testcase_04 | AC | 189 ms
53,764 KB |
testcase_05 | AC | 204 ms
58,072 KB |
testcase_06 | AC | 160 ms
53,880 KB |
testcase_07 | AC | 173 ms
53,840 KB |
testcase_08 | AC | 132 ms
53,956 KB |
testcase_09 | AC | 152 ms
54,116 KB |
testcase_10 | AC | 232 ms
56,244 KB |
testcase_11 | AC | 200 ms
55,896 KB |
testcase_12 | AC | 101 ms
52,960 KB |
testcase_13 | AC | 108 ms
53,868 KB |
testcase_14 | AC | 108 ms
53,884 KB |
testcase_15 | AC | 97 ms
53,024 KB |
testcase_16 | AC | 248 ms
56,292 KB |
testcase_17 | AC | 223 ms
55,896 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); No1050ZeroMaximum solver = new No1050ZeroMaximum(); solver.solve(1, in, out); out.close(); } static class No1050ZeroMaximum { public void solve(int testNumber, Scanner in, PrintWriter out) { final int MOD = (int) 1e9 + 7; int m = in.nextInt(); int k = in.nextInt(); // 最右項, 始めは1,0,0,0...0 long[][] res = new long[m][1]; res[0][0] = 1; // i->jに行く組み合わせ.addがあるので全て1からスタートする. long[][] mt = new long[m][m]; ArrayUtil.fill(mt, 1); for (int from = 0; from < m; from++) { for (int mul = 0; mul < m; mul++) { mt[from][(from * mul) % m]++; } } Matrix ans = Matrix.mul(Matrix.pow(new Matrix(mt), k, MOD), new Matrix(res), MOD); out.println(ans.m[0][0]); } } static class ArrayUtil { public static void fill(long[][] array, long val) { for (long[] a : array) Arrays.fill(a, val); } } static class Matrix { public long[][] m; public int h; public int w; public Matrix(int h, int w, long[][] m) { this.h = h; this.w = w; this.m = m; } public Matrix(long[][] m) { this.m = m; this.h = m.length; this.w = m[0].length; } public static Matrix identity(int n) { long[][] mat = new long[n][n]; for (int i = 0; i < n; i++) { mat[i][i] = 1; } return new Matrix(mat); } public static Matrix mul(Matrix m1, Matrix m2, long MOD) { long[][] res = new long[m1.h][m2.w]; long[][] mat1 = m1.m; long[][] mat2 = m2.m; for (int h = 0; h < m1.h; h++) { for (int w = 0; w < m2.w; w++) { for (int x = 0; x < m1.w; x++) { res[h][w] += mat1[h][x] * mat2[x][w]; res[h][w] %= MOD; } } } return new Matrix(res); } public static Matrix pow(Matrix m, long a, long MOD) { if (a == 0) return identity(m.h); Matrix half = pow(m, a / 2, MOD); return mul(mul(half, half, MOD), a % 2 == 0 ? identity(m.h) : m, MOD); } } }