結果

問題 No.2378 Cards and Subsequences
ユーザー kotatsugamekotatsugame
提出日時 2023-07-07 22:10:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 69,960 KB
実行使用メモリ 19,348 KB
最終ジャッジ日時 2023-09-28 23:31:07
合計ジャッジ時間 4,489 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,004 KB
testcase_01 AC 7 ms
19,004 KB
testcase_02 AC 7 ms
19,212 KB
testcase_03 AC 8 ms
19,208 KB
testcase_04 AC 9 ms
19,152 KB
testcase_05 AC 8 ms
19,016 KB
testcase_06 AC 11 ms
19,076 KB
testcase_07 AC 15 ms
19,056 KB
testcase_08 AC 16 ms
19,028 KB
testcase_09 AC 15 ms
19,128 KB
testcase_10 AC 10 ms
19,012 KB
testcase_11 AC 93 ms
19,148 KB
testcase_12 AC 92 ms
19,096 KB
testcase_13 AC 92 ms
19,064 KB
testcase_14 AC 89 ms
19,044 KB
testcase_15 AC 91 ms
19,084 KB
testcase_16 AC 90 ms
19,296 KB
testcase_17 AC 91 ms
18,996 KB
testcase_18 AC 91 ms
19,088 KB
testcase_19 AC 90 ms
19,080 KB
testcase_20 AC 90 ms
19,060 KB
testcase_21 AC 72 ms
19,232 KB
testcase_22 AC 72 ms
19,036 KB
testcase_23 AC 72 ms
19,308 KB
testcase_24 AC 72 ms
19,152 KB
testcase_25 AC 72 ms
19,016 KB
testcase_26 AC 110 ms
19,000 KB
testcase_27 AC 111 ms
19,080 KB
testcase_28 AC 111 ms
19,064 KB
testcase_29 AC 116 ms
19,032 KB
testcase_30 AC 112 ms
19,348 KB
testcase_31 AC 103 ms
19,012 KB
testcase_32 AC 43 ms
19,072 KB
testcase_33 AC 79 ms
19,092 KB
testcase_34 AC 78 ms
19,104 KB
testcase_35 AC 78 ms
19,032 KB
testcase_36 AC 79 ms
19,012 KB
testcase_37 AC 10 ms
19,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N,M,K;
int S[2000],A[2000],B[2000];
mint dp[2001][2001];
int prv[2000];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M>>K;
	for(int i=0;i<N;i++)cin>>S[i],S[i]--;
	for(int i=0;i<M;i++)cin>>A[i];
	for(int i=0;i<M;i++)cin>>B[i];
	for(int i=0;i<M;i++)prv[i]=-1;
	for(int i=0;i<N;i++)
	{
		int a=A[S[i]],b=B[S[i]];
		for(int j=0;j+a<=K||j+b<=K;j++)
		{
			mint now=dp[j][i];
			if(prv[S[i]]==-1)
			{
				if(j==0)now++;
			}
			else now-=dp[j][prv[S[i]]];
			if(j+a<=K)dp[j+a][i+1]+=now;
			if(j+b<=K)dp[j+b][i+1]+=now;
		}
		for(int j=0;j<=K;j++)dp[j][i+1]+=dp[j][i];
		prv[S[i]]=i;
	}
	cout<<dp[K][N].val()<<endl;
}
0