結果

問題 No.2310 [Cherry 5th Tune A] Against Regret
ユーザー shobonvipshobonvip
提出日時 2023-05-19 22:54:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,067 bytes
コンパイル時間 4,048 ms
コンパイル使用メモリ 235,420 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-10 06:21:34
合計ジャッジ時間 22,527 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 4 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 420 ms
5,376 KB
testcase_09 AC 1,015 ms
5,376 KB
testcase_10 AC 1,369 ms
5,376 KB
testcase_11 AC 570 ms
5,376 KB
testcase_12 AC 2,263 ms
5,376 KB
testcase_13 AC 228 ms
5,376 KB
testcase_14 AC 420 ms
5,376 KB
testcase_15 AC 857 ms
5,376 KB
testcase_16 AC 78 ms
5,376 KB
testcase_17 AC 764 ms
5,376 KB
testcase_18 AC 4,945 ms
5,376 KB
testcase_19 AC 4,987 ms
5,376 KB
testcase_20 TLE -
testcase_21 AC 5,065 ms
5,376 KB
testcase_22 AC 5,004 ms
5,376 KB
testcase_23 AC 5,076 ms
5,376 KB
testcase_24 AC 5,064 ms
5,376 KB
testcase_25 AC 4,982 ms
5,376 KB
testcase_26 AC 5,103 ms
5,376 KB
testcase_27 AC 5,076 ms
5,376 KB
testcase_28 AC 5,028 ms
5,376 KB
testcase_29 AC 294 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	vector<vector<int>> xx(n+1, vector<int>(n+1));
	for (int i=0; i<n+1; i++){
		for (int j=0; j<n+1; j++){
			cin >> xx[i][j];
		}
	}
	vector<vector<mint>> f(n+1, vector<mint>(0));
	for (int i=1; i<n+1; i++){
		f[i].resize(i);
		for (int j=0; j<i; j++){
			f[i][j] = xx[j][i];
		}
	}
	int q; cin >> q;
	for (int num=0; num<q; num++){
		int k; cin >> k;
		vector<vector<pair<int,mint>>> g(n+1, vector<pair<int,mint>>(0));
		for (int j=0; j<k; j++){
			int a, b, c; cin >> a >> b >> c;
			g[b].push_back(pair(a, c));
		}
		vector<mint> dp(n+1);
		dp[0] = 1;
		for (int i=1; i<n+1; i++){
			for (int j=0; j<i; j++){
				dp[i] += f[i][j] * dp[j];
			}
			for (auto [b, c]: g[i]){
				dp[i] += c * dp[b];
			}
		}
		cout << dp[n].val() << endl;
	}
}
0