結果

問題 No.1112 冥界の音楽
ユーザー momoyuumomoyuu
提出日時 2022-08-18 18:15:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,821 bytes
コンパイル時間 3,809 ms
コンパイル使用メモリ 282,844 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 02:08:06
合計ジャッジ時間 5,252 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
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 WA -
権限があれば一括ダウンロードができます

ソースコード

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];

vvi mattimes(vvi A,vvi B,ll mod = 1){
    vvi now(A.size(),vi(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;
}

vi mattimes(vvi A,vi B,ll mod = 1){
    vi 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]--;}

    vvi mat(K*K,vi(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;
    vvi A(K*K,vi(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 ++ ;
    }

    vi ans(K*K,0);
    rep(i,0,K){
        ans[i] = 1;
    }
    ans = mattimes(A,ans,mod);

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

    print(count);

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