結果

問題 No.1112 冥界の音楽
ユーザー cn_449cn_449
提出日時 2020-07-10 21:53:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,493 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 122,344 KB
実行使用メモリ 9,980 KB
最終ジャッジ日時 2023-08-01 21:51:50
合計ジャッジ時間 18,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
9,944 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 322 ms
5,264 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 232 ms
5,184 KB
testcase_05 AC 186 ms
5,592 KB
testcase_06 AC 186 ms
5,188 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 95 ms
5,464 KB
testcase_10 AC 186 ms
5,184 KB
testcase_11 AC 233 ms
5,200 KB
testcase_12 AC 234 ms
5,268 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1,148 ms
5,512 KB
testcase_15 AC 917 ms
5,268 KB
testcase_16 AC 1,101 ms
5,516 KB
testcase_17 AC 1,194 ms
5,280 KB
testcase_18 AC 1,193 ms
5,504 KB
testcase_19 AC 964 ms
5,128 KB
testcase_20 AC 1,144 ms
5,432 KB
testcase_21 AC 1,098 ms
5,488 KB
testcase_22 AC 1,053 ms
5,524 KB
testcase_23 AC 832 ms
5,512 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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(216, vector<ll>(216));
	vector<ll> cnt(216);
	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 = 36 * a[i].x + 6 * a[i].y + a[i].z;
				int numj = 36 * a[j].x + 6 * a[j].y + a[j].z;
				mat[numj][numi]++;
			}
		}
	}
	mat = mat_pow(mat, n - 3);
	ll ans = 0;
	rep(i, 216) {
		rep(j, 216) {
			if (i % 6 == 0) ans += mat[i][j] * cnt[j] % mod;
		}
	}
	cout << ans % mod << '\n';
}
0