QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#277861#4377. BackpackchunzhifengWA 400ms57428kbC++141.2kb2023-12-07 00:22:282023-12-07 00:22:29

Judging History

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

  • [2023-12-07 00:22:29]
  • 评测
  • 测评结果:WA
  • 用时:400ms
  • 内存:57428kb
  • [2023-12-07 00:22:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define PII pair<int,int>
const ll INF=0x3f3f3f3f;//3f3f3f3f;
const int mod=1e9+7;
const int N=2e6+5;
struct LineBase{
	int p[13];
	void clear(){
		memset(p,0,sizeof p);
	}
	void insert(ll x){
		for(int i=12;~i;--i){
			if(!(x>>i)) continue;
			if(!p[i]){
				p[i]=x; break;
			} x^=p[i];
		}
	}
	int query(){
		int ans=0;
		for(int i=12;~i;i--) ans=max(ans,ans^p[i]);
		return ans;
	}
}f[1035][1035];
void merge(LineBase &t1,LineBase &t2){
	for(int i=0;i<=12;i++) t1.insert(t2.p[i]);
}
bitset<1035>dp;
void solve(){
	int n,m; cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=m;j++) f[i][j].clear();
	}
	dp.reset();
	dp[0]=1;
	for(int i=1;i<=n;i++){
		int v,w; cin>>v>>w;
		for(int j=0;j<=m;j++) f[i][j]=f[i-1][j];
		for(int j=m;j>=v;j--) if(dp[j-v]) dp[j]=1;
		for(int j=v;j<=m;j++){
			merge(f[i][j],f[i-1][j-v]);
			f[i][j].insert(w);
		}
	} 
	if(dp[m]) cout<<f[n][m].query()<<endl;
	else cout<<-1<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T=1; cin>>T;
    while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 400ms
memory: 57428kb

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
577

result:

wrong answer 10th lines differ - expected: '513', found: '577'