結果

問題 No.1112 冥界の音楽
ユーザー 👑 NachiaNachia
提出日時 2020-10-24 19:42:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,337 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 166,556 KB
実行使用メモリ 5,492 KB
最終ジャッジ日時 2023-09-28 20:41:46
合計ジャッジ時間 3,873 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 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,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 14 ms
5,432 KB
testcase_25 AC 13 ms
5,208 KB
testcase_26 AC 12 ms
5,492 KB
testcase_27 AC 12 ms
5,128 KB
testcase_28 AC 13 ms
5,168 KB
testcase_29 AC 13 ms
5,392 KB
testcase_30 AC 12 ms
5,240 KB
testcase_31 AC 12 ms
5,192 KB
testcase_32 AC 13 ms
5,136 KB
testcase_33 AC 12 ms
5,220 KB
testcase_34 AC 12 ms
5,176 KB
testcase_35 AC 13 ms
5,196 KB
testcase_36 AC 13 ms
5,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

template<ULL M>
struct modint {
    ULL x;
    modint(ULL val = 0) : x(val) {}

    modint& operator+=(modint r) { x += r.x; if (x >= M) x -= M; return *this; }
    modint operator+(modint r) const { modint res = x; return res += r; }
    modint& operator-=(modint r) { x += M - r.x; if (x >= M) x -= M; return *this; }
    modint operator-(modint r) const { modint res = x; return res -= r; }
    modint& operator*=(modint r) { x = x * r.x % M; return *this; }
    modint operator*(modint r) const { return modint(x * r.x % M); }
    modint operator^(ULL r) const {
        if (r == 0) return modint(1);
        modint res = (*this * *this) ^ (r / 2);
        if (r % 2) res *= *this;
        return res;
    }
    modint& operator^=(ULL r) { return *this = *this ^ r; }
    modint& operator/=(modint r) { *this *= r ^ (M - 1); return *this; }
    modint operator/(modint r) const { return *this * (r ^ (M - 2)); }
    ULL& operator*() { return x; }
    const ULL& operator*() const { return x; }
    bool operator==(ULL r) const { return x == r; }
    bool operator!=(ULL r) const { return x != r; }
};

template<class Elem, size_t matrix_sz>
struct Matrix {
    Elem X[matrix_sz][matrix_sz] = {};
    static Matrix id() { Matrix res; rep(i, matrix_sz) res[i][i] = 1; return res; }
    Elem* operator[](int x) { return X[x]; }
    const Elem* operator[](int x) const { return X[x]; }
    Matrix operator*(Matrix r) const {
        Matrix res;
        rep(i, matrix_sz) rep(j, matrix_sz) rep(k, matrix_sz)
            res[i][j] += (*this)[i][k] * r[k][j];
        return res;
    }
    Matrix pow(ULL N) const {
        if (N == 0) return id();
        Matrix res = pow(N / 2);
        res = res * res;
        if (N % 2 == 1) res = res * *this;
        return res;
    }
};

const ULL M = 1000000007;
const int matrix_sz = 36;
using MLL = modint<M>;
using xMat = Matrix<MLL, matrix_sz>;

int main() {
    ULL K, J, N; cin >> K >> J >> N;

    xMat G;
    rep(j, J) {
        int u, v, w; cin >> u >> v >> w; u--; v--; w--;
        G[u * K + v][v * K + w] = 1;
    }

    G = G.pow(N - 2);
    MLL ans = 0;
    rep(i, K) rep(j, K) ans += G[i][j * K];
    cout << *ans << endl;

    return 0;
}
0