結果

問題 No.1112 冥界の音楽
ユーザー snrnsidysnrnsidy
提出日時 2021-06-14 01:43:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,354 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 206,192 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-25 10:35:45
合計ジャッジ時間 7,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 28 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 147 ms
4,380 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 38 ms
4,380 KB
testcase_18 AC 36 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 109 ms
4,376 KB
testcase_22 AC 159 ms
4,376 KB
testcase_23 AC 29 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 100 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 109 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long int MOD = 1e9 + 7;
int p[216], q[216], r[216];
long long int k, m, n;

vector <vector<long long int>> mul(vector <vector<long long int>> a, vector<vector<long long int>> b)
{
	int n = a.size();
	int m = a[0].size();
	int k = b[0].size();
	vector <vector<long long int>>c(n, vector<long long int>(k, 0));

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < k; j++)
		{
			for (int k = 0; k < m; k++)
			{
				c[i][j] += ((a[i][k]) * (b[k][j]));
				c[i][j] %= MOD;
			}
		}
	}

	return c;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> k >> m >> n;
	vector <vector<long long int>> a(m, vector<long long int>(m, 0));
	vector <vector<long long int>> b(m, vector<long long int>(m, 0));
    for (int i = 0; i < m; i++)
    {
		cin >> p[i] >> q[i] >> r[i];
    }

	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			if (q[i] == p[j] && r[i] == q[j])
			{
				//cout << i << ' ' << j << '\n';
				a[i][j] += 1;
			}
		}
		b[i][i] = 1;
	}
	
	n -= 3;
	while (n > 0)
	{
		if (n % 2 == 1)
		{
			b = mul(a, b);
		}
		a = mul(a, a);
		n /= 2;
	}

	long long int res = 0;

	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (p[i] == 1 && r[j] == 1) res += b[i][j]; res %= MOD;
		}
	}

	cout << res << '\n';

    return 0;
}
0