結果

問題 No.1112 冥界の音楽
ユーザー roarisroaris
提出日時 2020-07-10 22:30:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,826 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 203,316 KB
実行使用メモリ 12,320 KB
最終ジャッジ日時 2024-04-19 17:43:16
合計ジャッジ時間 12,307 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
//#define int long long
typedef vector<long long> vec;
typedef vector<vec> mat;
const long long MOD = 1000000007;

int K, M;
long long N;
int serial[10][10][10];
bool ok[220];

mat mat_mul(mat A, mat B) {
    mat C(A.size(), vec(B[0].size()));
    
    for (int i=0; i<A.size(); i++) {
        for (int j=0; j<B[0].size(); j++) {
            for (int k=0; k<A[0].size(); k++) {
                C[i][j] += A[i][k]*B[k][j];
                C[i][j] %= MOD;
            }
        }
    }
    
    return C;
}

mat mat_pow(mat A, long long n) {
    mat res(A.size(), vec(A.size()));
    
    for (int i=0; i<A.size(); i++) {
        res[i][i] = 1;
    }
    
    while (n > 0) {
        if (n & 1) {
            res = mat_mul(A, res);
        }
        
        n >>= 1;
        A = mat_mul(A, A);
    }
    
    return res;
}
 
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> K >> M >> N;
    if (N==3) {
        int ans = 0;
        rep(i, M) {
            int P, Q, R; cin >> P >> Q >> R;
            if (P==1 && R==1) ans++;
        }
        cout << ans << endl;
        exit(0);
    }
    
    int c = 0;
    rep(i, K) rep(j, K) rep(k, K) {
        serial[i][j][k] = c;
        c++;
    }
    rep(i, M) {
        int P, Q, R; cin >> P >> Q >> R;
        ok[serial[P-1][Q-1][R-1]] = true;
    }
    mat A(c, vec(c));
    rep(i, K) rep(j, K) rep(k, K) rep(l, K) {
        if (ok[serial[i][j][k]] && ok[serial[j][k][l]]) {
            A[serial[i][j][k]][serial[j][k][l]] = 1;
        }
    }
    mat res = mat_pow(A, N-3);
    long long ans = 0;
    rep(i, K) rep(j, K) rep(k, K) rep(l, K) {
        ans += res[serial[0][i][j]][serial[k][l][0]];
        ans %= MOD;
    }
    cout << ans << endl;
}
0