結果

問題 No.1112 冥界の音楽
ユーザー どららどらら
提出日時 2020-07-10 23:35:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,523 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 175,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 00:15:51
合計ジャッジ時間 4,777 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
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 WA -
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

typedef vector<ll> vec;
typedef vector<vec> mat;
const ll MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(), vec(B[0].size()));
  rep(i,A.size()) rep(k,B.size()){
    rep(j,B[0].size()){
      C[i][j] = (C[i][j]+A[i][k]*B[k][j])%MOD;
    }
  }
  return C;
}
mat pow(mat A, ll n){
  mat B(A.size(), vec(A.size()));
  rep(i,A.size()) B[i][i] = 1;
  while(n>0){
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n>>=1;
  }
  return B;
}
vector<ll> mulv(mat &A, vector<ll> v){
  vector<ll> ret = v;
  rep(i,v.size()){
    ll res = 0;
    rep(j,v.size()){ res += A[i][j]*v[j]; res = res%MOD; }
    ret[i] = res%MOD;
  }
  return ret;
}

int main(){
  int K, M;
  ll N;
  cin >> K >> M >> N;
  vector<vector<int>> v;
  rep(i,M){
    int p, q, r;
    cin >> p >> q >> r;
    v.push_back({p,q,r});
  }

  vector<int> gl;
  mat A(M, vec(M, 0));
  vec x(M, 0);
  
  rep(i,M){
    if(v[i][0] == 1) x[i] = 1;
    if(v[i][2] == 1) gl.push_back(i);
    
    rep(j,M){
      if(v[i][1] == v[j][0] && v[i][2] == v[j][1]){
        A[i][j] = 1;
      }
    }
  }
  
  N-=2;

  mat B = pow(A, N);
  vec y = mulv(B, x);

  ll ans = 0;
  rep(i,gl.size()){
    ans += y[gl[i]];
    ans %= MOD;
  }
  cout << ans << endl;
  
  return 0;
}


0