QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210461#4377. BackpackhazeAC ✓184ms4012kbC++201.3kb2023-10-11 14:51:152023-10-11 14:51:15

Judging History

你现在查看的是最新测评结果

  • [2023-10-11 14:51:15]
  • 评测
  • 测评结果:AC
  • 用时:184ms
  • 内存:4012kb
  • [2023-10-11 14:51:15]
  • 提交

answer

#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(Abs(pp),Abs(qq)):(pp)/(qq))
#define ll long long
#define LL __int128
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
	char ch = getchar();
	ll s = 0; bool w = 0;
	while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
	while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return w ? - s : s;
}

const int itinf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;

inline int mul(int nma, int nmb){
	return ((1ll * nma * nmb % mod) + mod) % mod;
}

void solve(){
	int n = read(), m = read();
	vector<bitset<1024>>f(1024),g(1024);
	/*
	f[xor][weight]
	*/
	f[0][0] = 1;
	for(int it = 0; it < n; ++ it){
		int w = read(), v = read();
		for(int xr = 1023 ; xr >= 0; -- xr){
			g[xr ^ v] = f[xr ^ v] | (f[xr] << w);
		}
		swap(f, g);
		g.resize(1024);
	}
	for(int i = 1023; i >= 0; -- i){
		if(g[i][m]){
			printf("%d\n", i);
			return;
		}
	}
	puts("-1");
	return;
}

int main(){
	int T = read();
	while(T --){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 184ms
memory: 4012kb

input:

10
1023 401
179 441
416 951
420 984
1013 984
683 914
407 984
96 523
374 190
974 190
739 441
518 523
194 984
415 523
149 441
235 984
809 441
469 441
436 919
437 919
7 919
818 984
962 190
37 919
371 523
417 914
431 914
213 190
340 441
254 919
223 951
123 190
339 951
322 441
218 441
284 919
533 190
187...

output:

1021
1011
-1
1023
1023
1023
1023
1023
1023
513

result:

ok 10 lines