QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614409 | #4377. Backpack | SSAABBEERR | AC ✓ | 199ms | 5948kb | C++20 | 803b | 2024-10-05 16:19:42 | 2024-10-05 16:19:43 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e6 + 10;
int n, m;
int v[N], w[N];
bitset<1024>f[2][1024];
void solve()
{
cin >> n >> m;
rep(i, 1, n)
{
cin >> v[i] >> w[i];
}
rep(i, 0, 1023)
{
rep(j, 0, 1)
f[j][i].reset();
}
f[0][0][0] = 1;
rep(i, 1, n)
{
rep(j, 0, 1023)
{
f[1][j] = f[0][j];
f[1][j] |= (f[0][j ^ w[i]] << v[i]);
}
rep(j, 0, 1023)
{
f[0][j] = f[1][j];
}
}
int ans = -1;
rep(i, 0, 1023) if(f[1][i][m]) ans = i;
cout << ans << endl;
}
int main()
{
IOS;
int _;
_ = 1;
cin >> _;
while(_--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 199ms
memory: 5948kb
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