結果

問題 No.1112 冥界の音楽
ユーザー pockynypockyny
提出日時 2021-12-18 06:05:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,878 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-10-13 10:05:56
合計ジャッジ時間 7,081 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<vector<ll>> vvl;
ll mod = 1000000007;
vvl mul(const vvl &a,const vvl &b){
    int i,j,k,n = a.size();
	vvl c(n,vector<ll>(n,0));
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++) (c[i][j] += a[i][k]*b[k][j]%mod) %= mod;
		}
	}
	return c;
}

vector<ll> mul2(vvl &a,vector<ll> b){
    int i,j,n = a.size();
    vector<ll> c(n);
    for(i=0;i<n;i++){
        for(j=0;j<a[i].size();j++) (c[i] += a[i][j]*b[j]%mod) %= mod;
    }
	return c;
}

vvl mat_pw(vvl &a, ll x){
    int i,j,k,n = a.size();
	vvl ret(n,vector<ll>(n,0));
	for(i=0;i<n;i++) ret[i][i] = 1;
	while(x){
        if(x&1) ret = mul(ret,a);
		a = mul(a,a); x /= 2;
	}
	return ret;
}

bool ok[6][6][6];
int main(){
    int i,j,l,r,k,m,n; cin >> k >> m >> n;
    for(i=0;i<k;i++){
        for(j=0;j<k;j++){
            for(l=0;l<k;l++) ok[i][j][l] = false; 
        }
    }
    for(i=0;i<m;i++){
        int p,q,r; cin >> p >> q >> r; p--; q--; r--;
        ok[p][q][r] = true;
    }
    int sz = k*k*k;
    vvl mat(sz);
    for(i=0;i<sz;i++) mat[i].resize(sz);
    for(i=0;i<k;i++){
        for(j=0;j<k;j++){
            for(l=0;l<k;l++){
                for(r=0;r<k;r++){
                    if(!ok[j][l][r]) continue;
                    int pos1 = k*k*i + k*j + l;
                    int pos2 = k*k*j + k*l + r;
                    mat[pos2][pos1] = 1;
                }
            }
        }
    }
    mat = mat_pw(mat,n - 3);
    vector<ll> v(sz);
    for(i=0;i<1;i++){
        for(j=0;j<k;j++){
            for(l=0;l<k;l++){
                if(ok[i][j][l]) v[k*k*i + j*k + l] = 1;
            }
        }
    }
    v = mul2(mat,v);
    ll ans = 0;
    for(i=0;i<k;i++){
        for(j=0;j<k;j++){
            for(l=0;l<1;l++) (ans += v[k*k*i + k*j + l]) %= mod;   
        }
    }
    cout << ans << endl;
}
0