結果

問題 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)
結果
AC  
実行時間 5,156 ms / 6,000 ms
コード長 1,067 bytes
コンパイル時間 3,299 ms
コンパイル使用メモリ 234,044 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-08-23 00:57:36
合計ジャッジ時間 71,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 4 ms
4,356 KB
testcase_06 AC 3 ms
4,360 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 430 ms
4,356 KB
testcase_09 AC 1,032 ms
4,356 KB
testcase_10 AC 1,376 ms
4,356 KB
testcase_11 AC 570 ms
4,356 KB
testcase_12 AC 2,299 ms
4,356 KB
testcase_13 AC 229 ms
4,356 KB
testcase_14 AC 420 ms
4,356 KB
testcase_15 AC 861 ms
4,352 KB
testcase_16 AC 79 ms
4,356 KB
testcase_17 AC 777 ms
4,356 KB
testcase_18 AC 5,138 ms
4,468 KB
testcase_19 AC 5,140 ms
4,448 KB
testcase_20 AC 5,156 ms
4,380 KB
testcase_21 AC 5,140 ms
4,448 KB
testcase_22 AC 5,133 ms
4,376 KB
testcase_23 AC 5,144 ms
4,416 KB
testcase_24 AC 5,150 ms
4,364 KB
testcase_25 AC 5,140 ms
4,380 KB
testcase_26 AC 5,132 ms
4,480 KB
testcase_27 AC 5,147 ms
4,484 KB
testcase_28 AC 5,137 ms
4,408 KB
testcase_29 AC 283 ms
4,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