結果
| 問題 |
No.1112 冥界の音楽
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-10 22:40:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 2,000 ms |
| コード長 | 2,450 bytes |
| コンパイル時間 | 1,201 ms |
| コンパイル使用メモリ | 115,788 KB |
| 最終ジャッジ日時 | 2025-01-11 18:54:26 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#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;
}