結果

問題 No.1112 冥界の音楽
ユーザー momoyuumomoyuu
提出日時 2022-08-18 18:18:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,878 bytes
コンパイル時間 3,524 ms
コンパイル使用メモリ 283,528 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 02:12:59
合計ジャッジ時間 4,888 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using vi = vc<int>;
using vvi = vvc<int>;

#define rep(i,a,b) for (int i = a; i < b; i++)
#define irep(i,a,b) for (int i = a; i > b; i--)
#define print(n) cout << n << endl
#define rup(a,b) (a+b-1)/b
#define input(A,N) rep(i,0,N) cin>>A[i];

vvc<ll> mattimes(vvc<ll> A,vvc<ll> B,ll mod = 1){
    vvc<ll> now(A.size(),vc<ll>(A.size(),0));
    rep(i,0,A.size()){
        rep(j,0,A.size()){
            rep(k,0,A.size()){
                now[i][j] += (A[i][k]*B[k][j])%mod;
                now[i][j] %= mod;
            }
        }
    }
    return now;
}

vc<ll> mattimes(vvc<ll> A,vc<ll> B,ll mod = 1){
    vc<ll> now(B.size(),0);
    rep(i,0,B.size()){
        rep(j,0,B.size()){
            now[i] += (A[i][j]*B[j])%mod;
            now[i] %= mod;
        }
    }
    return now;
}
int main(){
    cout << fixed << setprecision(15);
    
    int K,M;
    ll N;
    cin>>K>>M>>N;
    int P[M],Q[M],R[M];
    rep(i,0,M) {cin>>P[i]>>Q[i]>>R[i];P[i]--;Q[i]--;R[i]--;}

    vvc<ll> mat(K*K,vc<ll>(K*K,0));
    rep(i,0,M){
        int p,q;
        p = P[i]*K + Q[i];
        q = Q[i]*K + R[i];
        mat[q][p] = 1;
    }
    ll mod = ll(pow(10,9)) + 7;
    vvc<ll> A(K*K,vc<ll>(K*K,0));
    rep(i,0,K*K) A[i][i] = 1;
    int now = 0;
    while (pow(2,now)<=N-2){
        if (N-2>>now & 1){
            A = mattimes(A,mat,mod);
        }
        mat = mattimes(mat,mat,mod);
        now ++ ;
    }

    vc<ll> ans(K*K,0);
    rep(i,0,K){
        ans[i] = 1;
    }
    ans = mattimes(A,ans,mod);

    ull count = 0;
    rep(i,0,K){
        count += ans[i*K];
        count %= mod;
    }

    print(count);

    
    //system("pause");
    return 0;
}
0