結果

問題 No.1112 冥界の音楽
ユーザー DriceDrice
提出日時 2020-07-10 22:19:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 34,816 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 17:31:14
合計ジャッジ時間 1,298 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<cstdio>
const long long mod = 1e9+7;
long long a[50][50], res[50][50], c[50][50];
long long org[50], ans[50];

void mul(long long u[50][50],long long v[50][50],int n){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            c[i][j] = 0;
            for(int k = 1; k <= n; k++){
                c[i][j] += u[i][k]*v[k][j]%mod;
                if(c[i][j]>=mod) c[i][j] -= mod; 
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++) u[i][j] = c[i][j];
    }
}

void power(long long u[50][50],long long b,int n){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++) res[i][j] = i==j;
    }
    while(b){
        if(b&1) mul(res,u,n);
        mul(u,u,n);
        b /= 2;
    }
}

int main(){
    int k,m; long long n;
    scanf("%d%d%lld",&k,&m,&n);
    for(int i = 0; i < m; i++){
        int p,q,r;
        scanf("%d%d%d",&p,&q,&r);
        int from = p*k+q, to = q*k+r;
        a[to][from] = 1;
        if(p==1){ 
            //printf("to = %d\n",to);
            org[to] = 1;
        }
    }
    n -= 3;
    int total = (k+1)*k;
    power(a,n,total);
    /*for(int i = 1; i <= total; i++){
        for(int j = 1; j <= total; j++) printf("%lld ",res[i][j]);
        printf("\n");
    }*/
    for(int i = 1; i <= total; i++){
        long long cur = 0;
        for(int j = 1; j <= total; j++){
            cur += org[j]*res[i][j]%mod;
            if(cur>=mod) cur -= mod;
        }
        ans[i] = cur;
    }
    long long sum = 0;
    for(int i = 1; i <= k; i++){
        int id = i*k+1;
        sum += ans[id];
        if(sum>=mod) sum -= mod;
    }
    printf("%lld\n",sum);
    return 0;
}
0