結果

問題 No.2378 Cards and Subsequences
ユーザー kotatsugamekotatsugame
提出日時 2023-07-07 22:02:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 73,164 KB
実行使用メモリ 19,188 KB
最終ジャッジ日時 2023-09-28 23:19:15
合計ジャッジ時間 10,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 13 ms
4,836 KB
testcase_07 AC 14 ms
5,284 KB
testcase_08 AC 19 ms
5,656 KB
testcase_09 AC 24 ms
6,060 KB
testcase_10 AC 5 ms
4,424 KB
testcase_11 AC 268 ms
19,060 KB
testcase_12 AC 261 ms
18,892 KB
testcase_13 AC 263 ms
19,004 KB
testcase_14 AC 247 ms
18,916 KB
testcase_15 AC 261 ms
18,896 KB
testcase_16 AC 256 ms
19,188 KB
testcase_17 AC 260 ms
19,104 KB
testcase_18 AC 254 ms
18,924 KB
testcase_19 AC 257 ms
19,072 KB
testcase_20 AC 261 ms
18,896 KB
testcase_21 AC 197 ms
18,936 KB
testcase_22 AC 198 ms
18,936 KB
testcase_23 AC 203 ms
18,916 KB
testcase_24 AC 205 ms
18,940 KB
testcase_25 AC 202 ms
19,000 KB
testcase_26 AC 435 ms
18,900 KB
testcase_27 AC 441 ms
19,076 KB
testcase_28 AC 431 ms
18,992 KB
testcase_29 AC 430 ms
18,908 KB
testcase_30 AC 438 ms
18,924 KB
testcase_31 AC 437 ms
19,076 KB
testcase_32 AC 24 ms
19,012 KB
testcase_33 AC 224 ms
18,908 KB
testcase_34 AC 230 ms
18,996 KB
testcase_35 AC 218 ms
19,004 KB
testcase_36 AC 222 ms
18,896 KB
testcase_37 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/modint>
#include<atcoder/fenwicktree>
using namespace std;
using mint=atcoder::modint998244353;
int N,M,K;
int S[2000],A[2000],B[2000];
atcoder::fenwick_tree<mint>dp[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<=K;i++)
	{
		dp[i]=atcoder::fenwick_tree<mint>(N);
	}
	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=0;
			if(prv[S[i]]==-1)
			{
				now=j==0;
				now+=dp[j].sum(0,i);
			}
			else
			{
				now=dp[j].sum(prv[S[i]],i);
			}
			if(j+a<=K)
			{
				dp[j+a].add(i,now);
			}
			if(j+b<=K)
			{
				dp[j+b].add(i,now);
			}
		}
		prv[S[i]]=i;
	}
	cout<<dp[K].sum(0,N).val()<<endl;
}
0