結果
| 問題 |
No.1050 Zero (Maximum)
|
| コンテスト | |
| ユーザー |
silviasetitech
|
| 提出日時 | 2020-05-10 10:25:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,121 bytes |
| コンパイル時間 | 2,308 ms |
| コンパイル使用メモリ | 79,508 KB |
| 実行使用メモリ | 69,056 KB |
| 最終ジャッジ日時 | 2024-07-07 06:09:07 |
| 合計ジャッジ時間 | 6,744 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 14 |
ソースコード
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) {
return a == 0 ? identity(m.h)
: mul(mul(pow(m, a / 2, MOD),
pow(m, a / 2, MOD), MOD),
a % 2 == 0
? identity(m.h)
: m, MOD);
}
}
}
silviasetitech