QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277867 | #4377. Backpack | chunzhifeng | WA | 301ms | 56860kb | C++14 | 1.3kb | 2023-12-07 00:53:36 | 2023-12-07 00:53:36 |
Judging History
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 LBase{
int d[13];
void clear() { memset(d,0,sizeof d);}
bool insert(int x) {
for(int i =12;i>=0;--i)
if (x & (1 << i)) {
if (d[i]) x ^= d[i];
else {d[i] = x; break;}
}
return x > 0;
}
int qmax() {
int x = 0;
for (int i = 12; i >= 0; --i)
if (d[i])
if ((x ^ d[i]) > x) x ^= d[i];
return x;
}
void merge(const LBase &a) {
for (int i = 12; i >= 0; --i)
if(a.d[i]) insert(a.d[i]);
}
}f[1028][1028];
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++){
f[i][j].merge(f[i-1][j-v]);
f[i][j].insert(w);
}
}
if(dp[m]) cout<<f[n][m].qmax()<<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();
}
详细
Test #1:
score: 0
Wrong Answer
time: 301ms
memory: 56860kb
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'