QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411205 | #8005. Crossing the Border | JohnAlfnov | TL | 1649ms | 36640kb | C++20 | 2.1kb | 2024-05-15 09:48:05 | 2024-05-15 09:48:06 |
Judging History
answer
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
struct apple{
int w,c;
bool operator<(const apple &other)const{
return c>other.c;
}
}e[25];
int z1[1<<11],z2[1<<11];
int h1[1<<11],h2[1<<11];
struct info{
int f1,f2;
info(int f1=0,int f2=0):f1(f1),f2(f2){}
void operator+=(info in){
if(f1>in.f1)f1=in.f1,f2=in.f2;
else if(f1==in.f1)f2=(f2+in.f2)%mod;
}
}f[1<<11][1<<11];
info operator+(info a,int b){
a.f1+=b;return a;
}
struct appel{
int a;info in;
appel(int a=0,info in=0):a(a),in(in){}
bool operator<(const appel &other)const{
return a<other.a;
}
}e1[3005];
struct appe{
int a;int b;
appe(int a=0,int b=0):a(a),b(b){}
bool operator<(const appe &other)const{
return a<other.a;
}
}e2[3005];
int main(){
int n,W;
scanf("%d%d",&n,&W);
for(int i=1;i<=n;++i)scanf("%d%d",&e[i].w,&e[i].c);
sort(e+1,e+n+1);
int n1=n>>1,n2=n-n1;
for(int i=0;i<(1<<n1);++i){
z1[i]=-1e9;h1[i]=0;
for(int j=1;j<=n1;++j)if((i>>(j-1))&1){
h1[i]+=e[j].w;z1[i]=max(z1[i],e[j].c);
}
}
for(int i=0;i<(1<<n2);++i){
z2[i]=-1e9;h2[i]=0;
for(int j=1;j<=n2;++j)if((i>>(j-1))&1){
h2[i]+=e[n1+j].w;z2[i]=max(z2[i],e[n1+j].c);
}
}
info dd;dd.f1=1e9,dd.f2=0;
for(int i=0;i<(1<<n1);++i)for(int j=0;j<(1<<n2);++j)
f[i][j]=dd;
f[0][0].f1=0,f[0][0].f2=1;
for(int i=1;i<(1<<n2);++i){
for(int j=i;j;j=(j-1)&i){
if(__builtin_ctz(i)==__builtin_ctz(j)){
if(h2[j]<=W)f[0][i]+=f[0][i^j]+z2[j];
}
}
}
for(int i=1;i<(1<<n1);++i)for(int ii=0;ii<(1<<n2);++ii){
int t1=0,t2=0;
for(int j=i;j;j=(j-1)&i){
if(__builtin_ctz(i)==__builtin_ctz(j)&&h1[j]<=W){
info nf=f[i^j][ii]+z1[j];
e1[++t1]=appel(h1[j],nf);
}
}
int i2=((1<<n2)-1)^ii;
for(int j=i2;;j=(j-1)&i2){
if(h2[j]<=W){
e2[++t2]=appe(W-h2[j],j);
}
if(!j)break;
}
sort(e1+1,e1+t1+1);
sort(e2+1,e2+t2+1);
int w=1;
info cs(1e9,0);
for(int z=1;z<=t2;++z){
while(w<=t1&&e1[w].a<=e2[z].a){
cs+=e1[w++].in;
}
f[i][ii|e2[z].b]+=cs;
}
}
info ff=f[(1<<n1)-1][(1<<n2)-1];
printf("%d %d\n",ff.f1,ff.f2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 36640kb
input:
5 5 3 5 1 4 2 3 2 2 2 1
output:
9 4
result:
ok 2 number(s): "9 4"
Test #2:
score: 0
Accepted
time: 216ms
memory: 36580kb
input:
18 10000000 956231 904623 1692946 1796774 1081323 1170319 3218792 2542661 3183376 3037270 1869132 1442561 35436 35018 1564635 1939950 1847344 2006043 755870 899310 1671882 2057413 1369264 1338951 3132483 3504034 2056224 1825640 1840949 1562071 1514040 1405352 2300821 2421801 2466540 3004920
output:
9391997 70
result:
ok 2 number(s): "9391997 70"
Test #3:
score: 0
Accepted
time: 1649ms
memory: 36576kb
input:
20 10000000 1289384 1416015 1692778 1966748 1747794 1708650 2885387 2925290 2516650 2410838 2202363 2092667 368691 407497 1897764 1902790 180541 224758 1089173 1075924 2005212 1743637 702568 566295 465783 369143 2722863 2902398 174068 150211 513930 519657 1634023 1313239 1133070 1040937 961394 11066...
output:
6331196 89
result:
ok 2 number(s): "6331196 89"
Test #4:
score: -100
Time Limit Exceeded
input:
21 10000000 1432782 1230128 1693282 1456826 605524 521515 2742745 3427204 2231114 2129928 2345527 2397808 511783 521160 2041234 2313965 2323807 2603481 1232121 1410811 719508 850004 416942 495559 2180169 2579591 1580089 1786914 2317568 2292171 1514260 1143717 1348703 1495001 562052 525544 2818854 23...