結果

問題 No.1112 冥界の音楽
ユーザー roarisroaris
提出日時 2020-07-10 22:27:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,793 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 206,960 KB
実行使用メモリ 9,744 KB
最終ジャッジ日時 2023-08-01 18:27:09
合計ジャッジ時間 12,947 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
9,744 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 189 ms
5,360 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 47 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1,161 ms
5,448 KB
testcase_15 AC 177 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 232 ms
4,384 KB
testcase_18 AC 232 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 31 ms
4,376 KB
testcase_21 AC 1,110 ms
5,372 KB
testcase_22 AC 1,065 ms
5,424 KB
testcase_23 AC 162 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 747 ms
4,424 KB
testcase_31 AC 9 ms
4,376 KB
testcase_32 AC 818 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,380 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<int> vec;
typedef vector<vec> mat;
const int MOD = 1000000007;

int K, M, 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, int 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;
}
 
signed 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);
    int 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