結果
| 問題 |
No.868 ハイパー部分和問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-23 23:37:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,124 ms / 7,000 ms |
| コード長 | 1,129 bytes |
| コンパイル時間 | 1,518 ms |
| コンパイル使用メモリ | 169,996 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-13 14:51:55 |
| 合計ジャッジ時間 | 14,997 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998462417;
ll modpow(ll x, ll n, ll mod = MOD) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
const int MAXK = 15000;
ll dp[MAXK + 1];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, K;
cin >> n >> K;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
dp[0] = 1;
for (int i = 0; i < n; i++) {
if (a[i] == 0) continue;
for (int j = K; j >= a[i]; j--) {
(dp[j] += dp[j - a[i]]) %= MOD;
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x, v;
cin >> x >> v;
x--;
for (int j = a[x]; j <= K; j++) {
if (a[x] == 0) break;
(dp[j] += (MOD - dp[j - a[x]])) %= MOD;
}
a[x] = v;
for (int j = K; j >= v; j--) {
if (v == 0) break;
(dp[j] += dp[j - v]) %= MOD;
}
cout << (dp[K] > 0) << "\n";
}
return 0;
}