結果

問題 No.1112 冥界の音楽
ユーザー trineutrontrineutron
提出日時 2019-10-03 23:43:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,657 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 173,616 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 06:07:29
合計ジャッジ時間 3,733 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 9 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 27 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const long long mod = 1000000007;

vector<vector<long long>> matmul(vector<vector<long long>> a, vector<vector<long long>> b) {
    int s = a.size();
    vector<vector<long long>> c(s, vector<long long>(s));
    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            for (int k = 0; k < s; k++) {
                c.at(i).at(k) += a.at(i).at(j) * b.at(j).at(k);
                c.at(i).at(k) %= mod;
            }
        }
    }
    return c;
}

vector<long long> vecmul(vector<vector<long long>> a, vector<long long> x) {
    int s = x.size();
    vector<long long> ans(s);
    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            ans.at(i) += a.at(i).at(j) * x.at(j);
            ans.at(i) %= mod;
        }
    }
    return ans;
}

int main() {
    long long k, m, n;
    cin >> k >> m >> n;
    vector<vector<long long>> mat(k * k, vector<long long>(k * k));
    vector<long long> x(k * k);
    for (int i = 0; i < m; i++) {
        int p, q, r;
        cin >> p >> q >> r;
        p--; q--; r--;
        mat.at(q * k + r).at(p * k + q) = 1;
        if (p == 0) {
            x.at(p * k + q) = 1;
        }
    }
    vector<vector<long long>> newmat(k * k, vector<long long>(k * k));
    for (int i = 0; i < k * k; i++) {
        newmat.at(i).at(i) = 1;
    }
    for (long long i = n - 2; i; i /= 2) {
        if (i & 1) newmat = matmul(newmat, mat);
        mat = matmul(mat, mat);
    }
    x = vecmul(newmat, x);
    long long ans = 0;
    for (int i = 0; i < k; i++) {
        ans += x.at(i * k);
        ans %= mod;
    }
    cout << ans << endl;
}
0