結果

問題 No.1112 冥界の音楽
ユーザー cn_449cn_449
提出日時 2020-07-10 21:58:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,461 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 125,256 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 17:03:02
合計ジャッジ時間 2,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;

vector<vector<ll>> mat_mul(vector<vector<ll>> a, vector<vector<ll>> b) {
	int n = a.size();
	vector<vector<ll>> ans(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}
	return ans;
}

vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll b) {
	int n = a.size();
	vector<vector<ll>> ans(n, vector<ll>(n));
	for (int i = 0; i < n; i++) ans[i][i] = 1;
	while (b) {
		if (b & 1) ans = mat_mul(ans, a);
		a = mat_mul(a, a);
		b >>= 1;
	}
	return ans;
}

struct str {
	int x, y, z;
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll k, m, n;
	cin >> k >> m >> n;
	vector<vector<ll>> mat(36, vector<ll>(36));
	vector<ll> cnt(36);
	vector<str> a(m);
	rep(i, m) {
		int p, q, r;
		cin >> p >> q >> r;
		p--; q--; r--;
		a[i] = { p,q,r };
		if (!p) cnt[6 * q + r]++;
	}
	rep(i, m) {
		rep(j, m) {
			if (a[i].y == a[j].x && a[i].z == a[j].y) {
				int numi = 6 * a[i].y + a[i].z;
				int numj = 6 * a[j].y + a[j].z;
				mat[numj][numi] = 1;
			}
		}
	}
	mat = mat_pow(mat, n - 3);
	ll ans = 0;
	rep(i, 36) {
		rep(j, 36) {
			if (i % 6 == 0) ans += mat[i][j] * cnt[j] % mod;
		}
	}
	cout << ans % mod << '\n';
}
0