結果
| 問題 |
No.1112 冥界の音楽
|
| コンテスト | |
| ユーザー |
T1610
|
| 提出日時 | 2020-07-13 00:10:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,796 bytes |
| コンパイル時間 | 1,791 ms |
| コンパイル使用メモリ | 173,084 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 08:38:21 |
| 合計ジャッジ時間 | 3,074 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 16 WA * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}
#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x)
#define dumpL(x)
#define LINE
#define LINEL
#define dumpV(v)
#define dumpVL(v)
#define STOP assert(false)
#endif
#define mp make_pair
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
out << '(' << a.fi << ", " << a.se << ')';
return out;
}
}
template <typename T, typename U> T pow_fast(T x, U n) {
T ret = (T)1;
while(n) {
if(n & (U)1) ret *= x;
x *= x;
n >>= 1;
}
return ret;
}
template <typename ModType, ModType MOD> struct ModInt {
ModType val;
ModInt() : val(0) {}
ModInt(ModType x) : val(x % MOD) {
if(val < 0) val += MOD;
};
operator ModType() const { return val; }
ModInt &operator+=(const ModInt &m) {
val += m.val;
if(val >= MOD) val -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &m) {
val -= m.val;
if(val < 0) val += MOD;
return *this;
}
ModInt &operator*=(const ModInt &m) {
(val *= m.val) %= MOD;
return *this;
}
ModInt &operator/=(const ModInt &m) {
*this *= m.inverse();
return *this;
}
ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; }
ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; }
ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; }
ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; }
ModInt inverse() const { return pow_fast(*this, MOD - 2); }
ModInt pow(ModType n) const {return pow_fast(*this, n); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
os << rhs.val;
return os;
}
friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
ModType value;
is >> value;
rhs = ModInt(value);
return is;
}
};
template <class T, int SZ>
struct Mat {
array<array<T, SZ>, SZ> d;
const int n;
Mat() : n(SZ) {
array<T, SZ> tmp;
d.fill(tmp);
}
Mat(const array<array<T, SZ>, SZ>& d) :n(SZ), d(d){}
Mat operator * (const Mat& mt) const {
Mat ret;
rep(i, SZ) rep(j, SZ) {
rep(k, SZ) {
ret.d[i][j] += (d[i][k] * mt.d[k][j]);
}
}
return ret;
}
Mat& operator *= (const Mat& mt) {
*this = *this * mt;
return *this;
}
Mat& operator = (const Mat& mt) {
d = mt.d;
return *this;
}
Mat(Mat&&)=default;
array<T, SZ>& operator [](const int n) {
return d[n];
}
Mat pow(ll n) const {
Mat tmp(this->d);
Mat<T, SZ> ret;
rep(i, SZ) ret.d[i][i] = 1LL;
while(n > 0) {
if(n&1LL) ret = ret * tmp;
tmp *= tmp;
n >>= 1;
}
return ret;
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll k, m, n;
cin >> k >> m >> n;
vector<vi> a(m, vi(3));
rep(i, m) {
rep(j, 3) {
cin >> a[i][j];
--a[i][j];
}
}
if(n == 3) {
int ans = 0;
rep(i, m) {
if(a[i].front() == 0 && a[i].front() == a[i].back()) ++ans;
}
cout << ans << '\n';
return 0;
}
using mint = ModInt<ll, MOD>;
const int K = 6;
Mat<mint, K*K> mt;
rep(i, m) rep(j, m) if(a[i][1] == a[j][0] && a[i][2] == a[j][1]) {
int x = a[i][0] * K + a[i][1];
int y = a[j][1] * K + a[j][2];
mt[x][y] = mint(1);
}
auto&& d = mt.pow(n-3);
mint ans = 0;
rep(i, K) {
int x = i;
rep(j, K) {
int y = j * K;
ans += d[x][y];
}
}
cout << ans << '\n';
return 0;
}
T1610