結果

問題 No.868 ハイパー部分和問題
ユーザー 👑 kmjpkmjp
提出日時 2019-08-16 23:00:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,749 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 171,808 KB
実行使用メモリ 8,056 KB
最終ジャッジ日時 2023-10-24 04:01:17
合計ジャッジ時間 123,566 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
7,996 KB
testcase_01 AC 42 ms
7,996 KB
testcase_02 AC 66 ms
7,996 KB
testcase_03 AC 33 ms
7,944 KB
testcase_04 AC 22 ms
7,944 KB
testcase_05 AC 21 ms
7,944 KB
testcase_06 AC 23 ms
7,944 KB
testcase_07 AC 23 ms
7,944 KB
testcase_08 AC 24 ms
7,944 KB
testcase_09 AC 23 ms
7,944 KB
testcase_10 AC 24 ms
7,944 KB
testcase_11 AC 23 ms
7,944 KB
testcase_12 AC 23 ms
7,944 KB
testcase_13 AC 24 ms
7,944 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 4,880 ms
7,996 KB
testcase_20 AC 4,888 ms
8,056 KB
testcase_21 AC 4,940 ms
7,996 KB
testcase_22 AC 4,919 ms
8,056 KB
testcase_23 AC 4,912 ms
7,996 KB
testcase_24 AC 4,888 ms
8,056 KB
testcase_25 AC 4,966 ms
7,996 KB
testcase_26 AC 4,892 ms
7,996 KB
testcase_27 AC 4,890 ms
7,996 KB
testcase_28 AC 4,890 ms
7,996 KB
testcase_29 AC 3,620 ms
7,896 KB
testcase_30 AC 3,597 ms
7,896 KB
testcase_31 AC 3,646 ms
7,896 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const int prime_max = 1000000;
vector<int> prime;
int NP,divp[prime_max];

void cprime() {
	if(NP) return;
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		//M[i]=NP;
		prime.push_back(i); NP++;
		for(ll j=1LL*i*i;j>=i&&j<prime_max;j+=i) if(divp[j]==0) divp[j]=i;
	}
}

int N,K;
int A[151515];
const int DI=125;
int ok[DI][15151];
ll dp[15151][2];
ll mo[2]={1000000007,1000000009};
int Q;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	
	cin>>N>>K;
	dp[0][0]=dp[0][1]=1;
	FOR(i,N) {
		cin>>A[i];
		if(A[i]) {
			for(x=15000-A[i];x>=0;x--) {
				(dp[x+A[i]][0]+=dp[x][0]*prime[i])%=mo[0];
				(dp[x+A[i]][1]+=dp[x][1]*prime[i])%=mo[1];
			}
		}
	}
	
	cin>>Q;
	while(Q--) {
		cin>>i>>y;
		i--;
		if(A[i]) {
			FOR(x,15000-A[i]+1) {
				(dp[x+A[i]][0]-=dp[x][0]*prime[i])%=mo[0];
				(dp[x+A[i]][1]-=dp[x][1]*prime[i])%=mo[1];
			}
		}
		A[i]=y;
		if(A[i]) {
			for(x=15000-A[i];x>=0;x--) {
				(dp[x+A[i]][0]+=dp[x][0]*prime[i])%=mo[0];
				(dp[x+A[i]][1]+=dp[x][1]*prime[i])%=mo[1];
			}
		}
		if(dp[K][0] && dp[K][1]) cout<<1<<endl;
		else cout<<0<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0