結果
| 問題 | No.2378 Cards and Subsequences |
| コンテスト | |
| ユーザー |
Magentor
|
| 提出日時 | 2023-06-26 22:11:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 2,000 ms |
| コード長 | 919 bytes |
| 記録 | |
| コンパイル時間 | 2,050 ms |
| コンパイル使用メモリ | 205,260 KB |
| 最終ジャッジ日時 | 2025-02-15 02:27:00 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint.hpp>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i, n) for (int i=0; i<n; i++)
int main() {
ll n,m,k;
cin >> n >> m >> k;
vector<ll> s(n), a(m), b(m);
rep(i, n) {
cin >> s[i];
s[i]--;
}
rep(i, m) cin >> a[i];
rep(i, m) cin >> b[i];
vector br(n+1, vector<ll>(m, 0));
for (int i = 1; i <= n; i++) {
rep(j, m) br[i][j] = br[i-1][j];
br[i][s[i-1]] = i;
}
vector dp(n+2, vector<mint>(k+1, 0));
dp[1][0] = 1;
for (int i=2; i < n+2; i++) rep(j, k+1) {
ll si = s[i-2];
ll bpos = br[i-2][si];
if (j - a[si] >= 0) dp[i][j] += dp[i-1][j-a[si]] - dp[bpos][j-a[si]];
if (j - b[si] >= 0) dp[i][j] += dp[i-1][j-b[si]] - dp[bpos][j-b[si]];
dp[i][j] += dp[i-1][j];
}
cout << dp[n+1][k].val() << '\n';
}
Magentor