結果

問題 No.2310 [Cherry 5th Tune A] Against Regret
ユーザー 👑 kmjpkmjp
提出日時 2023-05-20 10:25:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 622 ms / 6,000 ms
コード長 1,581 bytes
コンパイル時間 3,210 ms
コンパイル使用メモリ 199,812 KB
実行使用メモリ 6,024 KB
最終ジャッジ日時 2023-08-23 07:55:21
合計ジャッジ時間 18,868 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 5 ms
4,356 KB
testcase_05 AC 4 ms
4,360 KB
testcase_06 AC 3 ms
4,360 KB
testcase_07 AC 3 ms
4,356 KB
testcase_08 AC 104 ms
5,432 KB
testcase_09 AC 145 ms
5,388 KB
testcase_10 AC 166 ms
5,472 KB
testcase_11 AC 204 ms
4,356 KB
testcase_12 AC 233 ms
5,292 KB
testcase_13 AC 100 ms
4,356 KB
testcase_14 AC 122 ms
4,380 KB
testcase_15 AC 227 ms
4,376 KB
testcase_16 AC 30 ms
4,380 KB
testcase_17 AC 126 ms
4,948 KB
testcase_18 AC 615 ms
5,728 KB
testcase_19 AC 614 ms
5,772 KB
testcase_20 AC 622 ms
5,796 KB
testcase_21 AC 616 ms
5,788 KB
testcase_22 AC 611 ms
5,776 KB
testcase_23 AC 611 ms
5,708 KB
testcase_24 AC 613 ms
5,844 KB
testcase_25 AC 614 ms
5,712 KB
testcase_26 AC 612 ms
5,792 KB
testcase_27 AC 613 ms
5,724 KB
testcase_28 AC 609 ms
6,024 KB
testcase_29 AC 421 ms
4,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
int X[500][500];
ll S[500][500];
const ll mo=998244353;
ll Y[35][35];
ll dp[55];
int K;
int A[55],B[55],C[55];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	N++;
	FOR(y,N) FOR(x,N) cin>>X[y][x];
	FOR(i,N) {
		S[i][i]=1;
		FOR(x,N) FOR(y,N) (S[i][y]+=S[i][x]*X[x][y])%=mo;
	}
	cin>>Q;
	while(Q--) {
		cin>>K;
		FOR(i,K) {
			cin>>A[i]>>B[i]>>C[i];
		}
		FOR(x,K) FOR(y,K-1) if(A[y]>A[y+1]) {
			swap(A[y],A[y+1]);
			swap(B[y],B[y+1]);
			swap(C[y],C[y+1]);
		}
		ZERO(Y);
		Y[0][K+1]=S[0][N-1];
		FOR(i,K) {
			Y[0][i+1]=S[0][A[i]];
			Y[i+1][K+1]=C[i]*S[B[i]][N-1]%mo;
			FOR(x,K) {
				Y[i+1][x+1]=C[i]*S[B[i]][A[x]]%mo;
			}
		}
		ZERO(dp);
		dp[0]=1;
		FOR(i,K+2) {
			for(x=i+1;x<K+2;x++) (dp[x]+=dp[i]*Y[i][x])%=mo;
		}
		cout<<dp[K+1]<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0