結果
| 問題 | No.2378 Cards and Subsequences | 
| コンテスト | |
| ユーザー |  沙耶花 | 
| 提出日時 | 2023-07-10 19:41:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 53 ms / 2,000 ms | 
| コード長 | 1,083 bytes | 
| コンパイル時間 | 4,065 ms | 
| コンパイル使用メモリ | 255,260 KB | 
| 最終ジャッジ日時 | 2025-02-15 09:37:05 | 
| ジャッジサーバーID (参考情報) | judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 35 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:41: warning: ‘d’ may be used uninitialized [-Wmaybe-uninitialized]
   46 |                                         if(d!=0){
      |                                         ^~
main.cpp:34:21: note: ‘d’ was declared here
   34 |                 int d;
      |                     ^
            
            ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int main(){
	int N,M,K;
	cin>>N>>M>>K;
	
	vector<int> s(N);
	rep(i,N){
		cin>>s[i];
		s[i]--;
	}
	vector<int> a(M),b(M);
	rep(i,M)cin>>a[i];
	rep(i,M)cin>>b[i];
	
	vector<vector<int>> is(M);
	rep(i,N){
		is[s[i]].push_back(i);
	}
	
	vector dp(N+1,vector<mint>(K+1,0));
	dp[0][0] = 1;
	mint ans = 0;
	rep(i,N){
		int d;
		rep(j,is[s[i]].size()){
			if(is[s[i]][j]==i){
				d = j;
				break;
			}
		}
		rep(j,K+1){
			{
				int x = j - a[s[i]];
				if(x>=0){
					dp[i+1][j] += dp[i][x];
					if(d!=0){
						dp[i+1][j] -= dp[is[s[i]][d-1]][x];
					}
				}
			}
			{
				int x = j - b[s[i]];
				if(x>=0){
					dp[i+1][j] += dp[i][x];
					if(d!=0){
						dp[i+1][j] -= dp[is[s[i]][d-1]][x];
					}
				}
			}
		}
		rep(j,K+1){
			if(j==K)ans += dp[i+1][j];
			dp[i+1][j] += dp[i][j];
		}
	}
	
	cout<<ans.val()<<endl;
	
	return 0;
}
            
            
            
        