結果
問題 | No.868 ハイパー部分和問題 |
ユーザー |
👑 |
提出日時 | 2019-08-17 01:01:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,540 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 129,300 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 07:50:12 |
合計ジャッジ時間 | 62,236 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 TLE * 2 |
ソースコード
#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <random> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; } template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; } int N, K; int A[20010]; int Q; int X[20010], V[20010]; int a[20010]; constexpr int H = 8; int MOs[10]; int dp[10][20010]; void init() { for (int h = 0; h < H; ++h) { fill(dp[h], dp[h] + K + 1, 0); dp[h][0] = 1; } } void add(int x) { if (x != 0) { for (int h = 0; h < H; ++h) { for (int j = K; j >= x; --j) { if ((dp[h][j] += dp[h][j - x]) >= MOs[h]) { dp[h][j] -= MOs[h]; } } } } } void remove(int x) { if (x != 0) { for (int h = 0; h < H; ++h) { for (int j = x; j <= K; ++j) { if ((dp[h][j] -= dp[h][j - x]) < 0) { dp[h][j] += MOs[h]; } } } } } int get() { for (int h = 0; h < H; ++h) { if (dp[h][K] != 0) { return 1; } } return 0; } int main() { MOs[0] = 998244353; MOs[1] = 1000000007; MOs[2] = 1000000009; random_device device; mt19937 rng(device()); uniform_int_distribution<int> distr(505005005, 1001001001); for (int h = 3; h < H; ++h) { MOs[h] = distr(rng); } // cerr<<"MOs = ";pv(MOs,MOs+H); for (; ~scanf("%d%d", &N, &K); ) { for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); } scanf("%d", &Q); for (int q = 0; q < Q; ++q) { scanf("%d%d", &X[q], &V[q]); --X[q]; } init(); for (int i = 0; i < N; ++i) { add(A[i]); } copy(A, A + N, a); for (int q = 0; q < Q; ++q) { remove(a[X[q]]); a[X[q]] = V[q]; add(a[X[q]]); // pv(a,a+N); // pv(dp[0],dp[0]+K+1); // pv(dp[1],dp[1]+K+1); printf("%d\n", get()); } } return 0; }