結果

問題 No.1112 冥界の音楽
ユーザー NewGardenNewGarden
提出日時 2020-07-10 22:40:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 2,450 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 120,012 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 18:43:21
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 20 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 17 ms
4,376 KB
testcase_20 AC 18 ms
4,380 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 19 ms
4,376 KB
testcase_23 AC 15 ms
4,376 KB
testcase_24 AC 71 ms
4,380 KB
testcase_25 AC 67 ms
4,376 KB
testcase_26 AC 62 ms
4,376 KB
testcase_27 AC 58 ms
4,376 KB
testcase_28 AC 68 ms
4,376 KB
testcase_29 AC 64 ms
4,380 KB
testcase_30 AC 61 ms
4,380 KB
testcase_31 AC 59 ms
4,376 KB
testcase_32 AC 67 ms
4,380 KB
testcase_33 AC 66 ms
4,376 KB
testcase_34 AC 60 ms
4,376 KB
testcase_35 AC 65 ms
4,376 KB
testcase_36 AC 75 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

// matrix pow mod
void matpom(ll*mat,int size,ll n,int m){
  ll*temp=(ll*)malloc(size*size*sizeof(ll));
  ll*ans=(ll*)malloc(size*size*sizeof(ll));  
  rep(i,size)rep(j,size)ans[i*size+j] = i==j;
  while(n){
    if(n%2){
      rep(i,size*size)temp[i]=0;
      rep(i,size)rep(j,size)rep(k,size)temp[i*size+j]=(temp[i*size+j]+ans[i*size+k]*mat[k*size+j])%m;
      rep(i,size*size)ans[i]=temp[i];
    }
    rep(i,size*size)temp[i]=0;
    rep(i,size)rep(j,size)rep(k,size)temp[i*size+j]=(temp[i*size+j]+mat[i*size+k]*mat[k*size+j])%m;
    rep(i,size*size)mat[i]=temp[i];
    n/=2;
  }
  rep(i,size*size)mat[i]=ans[i];
  free(temp); free(ans);
}

int main(){
  ll n,m,k;
  cin >> k >> m >> n;
  ll v[36][36];
  rep(i,36)rep(j,36){ v[i][j] = 0; }
  rep(i,m){
    int a,b,c; cin >> a >> b >> c; a--; b--; c--;
    v[a+b*6][b+c*6] = 1;
  }
  matpom((ll*)v,36,n-2,mod);
  mint ans = 0;
  rep(i,6)rep(j,6){
    ans += v[0+i*6][j+0*6];
  }
  cout << ans.x << ln;


  return 0;
}
0