結果

問題 No.868 ハイパー部分和問題
ユーザー chocoruskchocorusk
提出日時 2019-08-17 01:31:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,778 ms / 7,000 ms
コード長 1,741 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 103,920 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:21:32
合計ジャッジ時間 23,645 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 991 ms
4,348 KB
testcase_15 AC 987 ms
4,348 KB
testcase_16 AC 990 ms
4,348 KB
testcase_17 AC 985 ms
4,348 KB
testcase_18 AC 992 ms
4,348 KB
testcase_19 AC 673 ms
4,348 KB
testcase_20 AC 674 ms
4,348 KB
testcase_21 AC 677 ms
4,348 KB
testcase_22 AC 673 ms
4,348 KB
testcase_23 AC 673 ms
4,348 KB
testcase_24 AC 674 ms
4,348 KB
testcase_25 AC 678 ms
4,348 KB
testcase_26 AC 674 ms
4,348 KB
testcase_27 AC 674 ms
4,348 KB
testcase_28 AC 674 ms
4,348 KB
testcase_29 AC 494 ms
4,348 KB
testcase_30 AC 491 ms
4,348 KB
testcase_31 AC 497 ms
4,348 KB
testcase_32 AC 986 ms
4,348 KB
testcase_33 AC 987 ms
4,348 KB
testcase_34 AC 1,778 ms
4,348 KB
testcase_35 AC 1,773 ms
4,348 KB
testcase_36 AC 1,088 ms
4,348 KB
testcase_37 AC 1,086 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int MOD[3];
bool isprime(int x){
	for(int i=2; i*i<=x; i++){
		if(x%i==0) return false;
	}
	return true;
}
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rndp(700000000, 1000000000);
int main()
{
	int n, k; cin>>n>>k;
	for(int i=0; i<3; i++){
		int x=rndp(mt);
		for(int j=x; ; j++){
			if(isprime(j)){
				MOD[i]=j;
              //cout<<j<<endl;
				break;
			}
		}
	}
	int a[15010], a0[15010];
	for(int i=0; i<n; i++) cin>>a[i], a0[i]=a[i];
	int q; cin>>q;
	int ans[15010]={};
	int x[15010], v[15010];
	for(int i=0; i<q; i++){
		cin>>x[i]>>v[i]; x[i]--;
	}
	for(int t=0; t<3; t++){
		int dp[15010]={};
		dp[0]=1;
		for(int i=0; i<n; i++){
			a[i]=a0[i];
			if(a[i]==0) continue;
			for(int j=k-a[i]; j>=0; j--){
				dp[j+a[i]]+=dp[j];
				if(dp[j+a[i]]>=MOD[t]) dp[j+a[i]]-=MOD[t];
			}
		}
		for(int i=0; i<q; i++){
			if(a[x[i]]!=0){
				for(int j=0; j<=k-a[x[i]]; j++){
					dp[j+a[x[i]]]+=(MOD[t]-dp[j]);
					if(dp[j+a[x[i]]]>=MOD[t]) dp[j+a[x[i]]]-=MOD[t];
				}
			}
			a[x[i]]=v[i];
			if(a[x[i]]!=0){
				for(int j=k-a[x[i]]; j>=0; j--){
					dp[j+a[x[i]]]+=dp[j];
					if(dp[j+a[x[i]]]>=MOD[t]) dp[j+a[x[i]]]-=MOD[t];
				}
			}
			if(dp[k]!=0) ans[i]=1;
		}
	}
	for(int i=0; i<q; i++) printf("%d\n", ans[i]);
	return 0;
}
0