結果

問題 No.1050 Zero (Maximum)
ユーザー わなわなわなわな
提出日時 2020-05-09 04:57:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 77,672 KB
実行使用メモリ 6,092 KB
最終ジャッジ日時 2023-09-17 22:35:23
合計ジャッジ時間 2,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 24 ms
4,380 KB
testcase_03 AC 18 ms
4,380 KB
testcase_04 AC 76 ms
5,180 KB
testcase_05 AC 82 ms
5,024 KB
testcase_06 AC 34 ms
4,380 KB
testcase_07 AC 44 ms
4,500 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 106 ms
5,540 KB
testcase_11 AC 72 ms
4,716 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 115 ms
5,200 KB
testcase_17 AC 129 ms
6,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long MOD = 1e9 + 7;
long long M, K;
vector<vector<long long>> gyo(vector<vector<long long>> a, vector<vector<long long>> b){
    vector<vector<long long>> A(M, vector<long long> (M));
    for(int i = 0; i < M; i++){
        for(int j = 0; j < M; j++){
            long long res = 0;
            for(int k = 0; k < M; k++){
                res += a[i][k]*b[k][j] % MOD;
                res %= MOD;
            }
            A[i][j] = res;
        }
    }
    return A;
}
vector<vector<long long>> repow(vector<vector<long long>> a, long long b){
    vector<vector<long long>>  B(M, vector<long long> (M));
    if(b == 1) return a;
    if(b % 2 == 0){
        B = repow(a, b/2);
        return gyo(B, B);
    }
    else return gyo(repow(a, b - 1), a);
}
int main(){
    cin >> M >> K;
    vector<vector<long long>> dp(M, vector<long long>(M,0));
    for(int i = 0; i < M; i++){
        for(int j = 0; j < M; j++){
            dp[i*j%M][i]++;
            dp[(i + j)%M][i]++;
        }
    }
    vector<vector<long long>> ans;
    ans = repow(dp, K);
    cout << ans[0][0] << endl;
}
0