QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110592 | #6194. Knapsack Problem | tuxiaoxiao | WA | 5ms | 3616kb | C++14 | 1.1kb | 2023-06-02 22:08:39 | 2023-06-02 22:08:43 |
Judging History
answer
#include<bits/stdc++.h>
#define f(i,x,y) for(int i=x;i<=y;i++)
#define df(i,x,y) for(int i=x;i>=y;i--)
#define int long long
#define pb push_back
using namespace std;
const int N=1.1e6,I=1e18;
int k,a[4],cs,x,al,y,c[16],f[8][8][8][8],a0,a1,a2,a3,ni,nj,nk,nl;
signed main()
{
scanf("%lld",&cs);
while(cs--)
{
scanf("%lld",&k);al=(1<<k)-1;
f(i,0,3)a[i]=0;f(i,0,15)c[i]=0;
f(i,1,al)scanf("%lld",&c[i]);
f(i,0,k-1)scanf("%lld",&a[i]);
memset(f,0xcf,sizeof(f));f[0][0][0][0]=0;
df(d,29,0)
{
a0=a[0]>>d&1;a1=a[1]>>d&1;a2=a[2]>>d&1;a3=a[3]>>d&1;
df(i,7-a0,0)df(j,7-a1,0)df(k,7-a2,0)df(l,7-a3,0)
{
if((i&1)|(j&1)|(k&1)|(l&1))f[i+a0][j+a1][k+a2][l+a3]=-I;
else f[i+a0][j+a1][k+a2][l+a3]=f[i/2][j/2][k/2][l/2];
f[i][j][k][l]=-I;
}
f(p,1,16)f(i,0,7)f(j,0,7)f(k,0,7)f(l,0,7)if(f[i][j][k][l]>=0)
{
ni=i-(p&1);nj=j-(p>>1&1);nk=k-(p>>2&1);nl=l-(p>>3&1);
if(ni>=0&&nj>=0&&nk>=0&&nl>=0)f[ni][nj][nk][nl]=max(f[i][j][k][l]+(c[p]<<d),f[ni][nj][nk][nl]);
}
}
cout<<f[0][0][0][0]<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 3616kb
input:
3 2 1 2 4 4 5 3 3226252 19270256 2430652 1187613 12496062 10286165 17494834 24 85 34 4 901133 6693218 13245489 14740234 16186210 11382783 19277321 3855635 16523184 10168517 16195031 971041 10303441 8395899 11618555 529321239 218214127 92942310 207467810
output:
-1000000000000000000 -1000000000000000000 -1000000000000000000
result:
wrong answer 1st numbers differ - expected: '18', found: '-1000000000000000000'