結果
問題 | No.868 ハイパー部分和問題 |
ユーザー |
![]() |
提出日時 | 2019-08-23 16:39:18 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,067 ms / 7,000 ms |
コード長 | 818 bytes |
コンパイル時間 | 570 ms |
コンパイル使用メモリ | 54,876 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 14:29:24 |
合計ジャッジ時間 | 13,902 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#include <iostream>#define llint long long#define mod 998244853using namespace std;llint n, Q, k;llint a[15005];llint dp[15005];int main(void){ios::sync_with_stdio(0);cin.tie(0);cin >> n >> k;for(int i = 1; i <= n; i++) cin >> a[i];dp[0] = 1;for(int i = 1; i <= n; i++){if(a[i] == 0 || a[i] > k) continue;for(int j = k; j >= 0; j--){if(j >= a[i]) dp[j] += dp[j-a[i]], dp[j] %= mod;}}cin >> Q;llint x, v;for(int q = 0; q < Q; q++){cin >> x >> v;if(a[x] && a[x] <= k){for(int i = a[x]; i <= k; i++){dp[i] += mod - dp[i-a[x]], dp[i] %= mod;}}a[x] = v;if(a[x] && a[x] <= k){for(int i = k; i >= a[x]; i--){dp[i] += dp[i-a[x]], dp[i] %= mod;}}if(dp[k]) cout << 1 << "\n";else cout << 0 << "\n";}flush(cout);return 0;}