結果

問題 No.868 ハイパー部分和問題
ユーザー autumn-eelautumn-eel
提出日時 2019-08-17 09:58:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,336 ms / 7,000 ms
コード長 759 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 167,432 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 23:58:04
合計ジャッジ時間 27,959 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1,092 ms
4,348 KB
testcase_15 AC 1,093 ms
4,348 KB
testcase_16 AC 1,093 ms
4,348 KB
testcase_17 AC 1,090 ms
4,348 KB
testcase_18 AC 1,097 ms
4,348 KB
testcase_19 AC 931 ms
4,348 KB
testcase_20 AC 928 ms
4,348 KB
testcase_21 AC 930 ms
4,348 KB
testcase_22 AC 935 ms
4,348 KB
testcase_23 AC 932 ms
4,348 KB
testcase_24 AC 931 ms
4,348 KB
testcase_25 AC 930 ms
4,348 KB
testcase_26 AC 933 ms
4,348 KB
testcase_27 AC 930 ms
4,348 KB
testcase_28 AC 929 ms
4,348 KB
testcase_29 AC 899 ms
4,348 KB
testcase_30 AC 883 ms
4,348 KB
testcase_31 AC 883 ms
4,348 KB
testcase_32 AC 1,092 ms
4,348 KB
testcase_33 AC 1,091 ms
4,348 KB
testcase_34 AC 1,336 ms
4,348 KB
testcase_35 AC 1,335 ms
4,348 KB
testcase_36 AC 1,142 ms
4,348 KB
testcase_37 AC 1,146 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll MOD=1000000007LL*100000007LL;

int a[20000];
ll dp[20000];
ll dp2[20000];

int main(){
	int n,K;cin>>n>>K;
	dp[0]=1;
	rep(i,n){
		scanf("%d",&a[i]);
		if(a[i]){
			for(int j=K;j>=a[i];j--){
				(dp[j]+=dp[j-a[i]])%=MOD;
			}
		}
	}
	int q;scanf("%d",&q);
	rep(i,q){
		int x,v;scanf("%d%d",&x,&v);x--;
		for(int i=0;i<=K;i++){
			if(a[x]){
				if(i<a[x])dp2[i]=dp[i];
				else dp2[i]=(dp[i]+MOD-dp2[i-a[x]])%MOD;
			}
			else dp2[i]=dp[i];
		}
		a[x]=v;
		for(int i=0;i<=K;i++){
			if(a[x]){
				if(i<a[x])dp[i]=dp2[i];
				else dp[i]=(dp2[i-a[x]]+dp2[i])%MOD;
			}
			else dp[i]=dp2[i];
		}
		puts(dp[K]?"1":"0");
	}
}
0