結果

問題 No.1050 Zero (Maximum)
ユーザー simkarensimkaren
提出日時 2020-05-27 12:03:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 190,380 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 05:08:50
合計ジャッジ時間 3,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 17 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 9 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 21 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 23 ms
5,376 KB
testcase_17 AC 27 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

constexpr ll mod = 1000000007LL;

struct Matrix {
    int n;
    vector<vector<ll>> element;

    Matrix(int n) : n(n) {
        element.resize(n);
        for (int i = 0; i < n; ++i)
            element[i].resize(n, 0);
    }

    Matrix operator *(Matrix a) {
        assert(n == a.n);
        Matrix res(n);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                ll tmp = 0;
                for (int k = 0; k < n; ++k) {
                    tmp += element[i][k] * a.element[k][j] % mod;
                    tmp %= mod;
                }
                res.element[i][j] = tmp;
            }
        }
        return res;
    }

    Matrix pow(ll k) {
        if (k == 0) {
            Matrix res(n);
            for (int i = 0; i < n; ++i)
                res.element[i][i] = 1;
            return res;
        }
        Matrix tmp = pow(k / 2);
        if (k % 2 == 1)
            return tmp * tmp * (*this);
        return tmp * tmp;
    }
};

int main(void){
    int M, K; cin >> M >> K;
    Matrix m(M);
    for (int i = 0; i < M; ++i)
        for (int p = 0; p < M; ++p)
            ++m.element[(i + p) % M][i],
            ++m.element[(i * p) % M][i];
    m = m.pow(K);
    cout << m.element[0][0] << endl;
    return 0;
}
0