結果
問題 | No.868 ハイパー部分和問題 |
ユーザー |
![]() |
提出日時 | 2019-08-17 01:18:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 829 ms / 7,000 ms |
コード長 | 2,142 bytes |
コンパイル時間 | 1,581 ms |
コンパイル使用メモリ | 172,760 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 08:36:44 |
合計ジャッジ時間 | 11,116 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long int;using pint = pair<int, int>;struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;#define ALL(x) (x).begin(), (x).end()#define SZ(x) ((lint)(x).size())#define POW2(n) (1LL << (n))#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)#define REP(i, n) FOR(i,0,n)#define IREP(i, n) IFOR(i,0,n)template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }///// This part below is only for debug, not used /////template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; returnos; }#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;///// END /////int N, K;vector<int> A;vector<lint> dp;constexpr lint MOD = 1111111111;void dp_add(int v){IFOR(i, v, dp.size()){dp[i] += dp[i - v];if (dp[i] >= MOD) dp[i] -= MOD;}}void dp_erase(int v){if (v == 0){REP(i, dp.size()) dp[i] = dp[i] * (1 + MOD) / 2 % MOD;return;}FOR(i, v, dp.size()){dp[i] += MOD - dp[i - v];if (dp[i] >= MOD) dp[i] -= MOD;}}int main(){cin >> N >> K;A.resize(N);cin >> A;dp.assign(K + 1, 0);dp[0] = 1;for (auto v : A) dp_add(v);int Q;cin >> Q;REP(_, Q){int x, v;cin >> x >> v;dp_erase(A[x - 1]);A[x - 1] = v;dp_add(A[x - 1]);cout << !!dp[K] << endl;// dbg(dp);}}