結果

問題 No.2310 [Cherry 5th Tune A] Against Regret
ユーザー kwm_tkwm_t
提出日時 2023-05-20 13:11:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,267 bytes
コンパイル時間 4,752 ms
コンパイル使用メモリ 271,692 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-01 06:59:30
合計ジャッジ時間 24,083 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 370 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:37: warning: 'idx1' may be used uninitialized [-Wmaybe-uninitialized]
   75 |                         x[idx0][idx1] += c[i];
      |                                     ^
main.cpp:69:35: note: 'idx1' was declared here
   69 |                         int idx0, idx1;
      |                                   ^~~~
main.cpp:74:35: warning: 'idx0' may be used uninitialized [-Wmaybe-uninitialized]
   74 |                         x[st][idx0] = dp[0][a[i]];
      |                                   ^
main.cpp:69:29: note: 'idx0' was declared here
   69 |                         int idx0, idx1;
      |                             ^~~~
main.cpp:66:37: warning: 'idx1' may be used uninitialized [-Wmaybe-uninitialized]
   66 |                         x[idx0][idx1] = dp[b[i]][a[j]];
      |                                     ^
main.cpp:59:35: note: 'idx1' was declared here
   59 |                         int idx0, idx1;
      |                                   ^~~~
main.cpp:66:31: warning: 'idx0' may be used uninitialized [-Wmaybe-uninitialized]
   66 |                         x[idx0][idx1] = dp[b[i]][a[j]];
      |                               ^
main.cpp:59:29: note: 'idx0' was declared here
   59 |                         int idx0, idx1;
      |                             ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector x(n + 1, vector<mint>(n + 1));
	rep(i, n + 1)rep(j, n + 1) {
		int _x; cin >> _x;
		x[i][j] = _x;
	}
	vector dp(n + 1, vector<mint>(n + 1));
	rep(i, n + 1) {
		dp[i][i] = 1;
		rep2(j, i, n + 1)rep2(k, j + 1, n + 1) {
			dp[i][k] += dp[i][j] * x[j][k];
		}
	}
	//cout << dp[0][n].val() << endl;
	int q; cin >> q;
	while (q--) {
		int k; cin >> k;
		vector<int>a(k), b(k), c(k);
		vector<int>v;
		rep(i, k) {
			cin >> a[i] >> b[i] >> c[i];
			v.push_back(a[i]);
			v.push_back(b[i]);
		}
		sort(all(v));
		v.erase(unique(all(v)), v.end());
		int st = 0;
		int ed = v.size() + 1;
		int sz = ed + 1;
		vector<mint>dp2(sz + 1);
		vector x(sz, vector<mint>(sz));
		x[st][ed] += dp[0][n];
		rep(i, k)rep(j, k) {
			if (!(b[i] < a[j]))continue;
			int idx0, idx1;
			rep(_k, v.size()) {
				if (b[i] == v[_k])idx0 = _k + 1;
				if (a[j] == v[_k])idx1 = _k + 1;
			}
			//cout << idx0 << " " << idx1 << endl;
			//cout << b[i] << "_" << b[j] << endl;
			x[idx0][idx1] = dp[b[i]][a[j]];
		}
		rep(i, k) {
			int idx0, idx1;
			rep(j, v.size()) {
				if (a[i] == v[j])idx0 = j + 1;
				if (b[i] == v[j])idx1 = j + 1;
			}
			x[st][idx0] = dp[0][a[i]];
			x[idx0][idx1] += c[i];
			x[idx1][ed] = dp[b[i]][n];
		}
		vector<mint>ans(sz);
		ans[0] = 1;
		rep(i, sz) {
			rep(j, sz) ans[j] += ans[i] * x[i][j];
		}
		cout << ans.back().val() << endl;
	}
	return 0;
}
0