QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#66926 | #5169. 夹娃娃 | Flamire | 0 | 13ms | 14240kb | C++14 | 2.9kb | 2022-12-09 13:08:45 | 2022-12-09 13:08:47 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,q,a[21],b[21][1011],lg[100011],c[21][1011],sum[1<<8][521][521],f[21][100011],nf[21][100011],prod[1<<8][521],pcnt[1<<8];char s[1011];
const int p=998244353;long long dp[1<<8][521][521];
namespace ntt
{
int q,ord[100011];const int G=3;
inline int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;ex>>=1;bs=1ll*bs*bs%p;}return ans;}
void ntt_init(int n,int m)
{
q=1;while(q<=n+m)q<<=1;
ord[0]=0;for(int i=1;i<q;++i)ord[i]=ord[i>>1]>>1|(i&1?q>>1:0);
}
void ntt(int *f,bool dft)
{
for(int i=0;i<q;++i)if(i<ord[i])swap(f[i],f[ord[i]]);
for(int len=2;len<=q;len<<=1)
{
int lp=len>>1,w=qpow(G,(p-1)/len);if(!dft)w=qpow(w,p-2);
for(int i=0;i<q;i+=len)
{
int cur=1;
for(int _=i;_<i+lp;++_)
{
int tmp=1ll*cur*f[_+lp]%p;
f[_+lp]=f[_]-tmp;f[_+lp]<0&&(f[_+lp]+=p);
f[_]+=tmp;f[_]>=p&&(f[_]-=p);cur=1ll*cur*w%p;
}
}
}
}
void mul(int *f,int n,int *g,int m)
{
ntt_init(n,m);
ntt(f,1);ntt(g,1);for(int i=0;i<q;++i)f[i]=1ll*f[i]*g[i]%p;ntt(f,0);
int iq=qpow(q,p-2);
for(int i=0;i<=n+m;++i)f[i]=1ll*f[i]*iq%p;
}
};
int main()
{
// f[0][0]=f[0][3]=f[0][6]=f[0][9]=f[0][12]=1;
// nf[0][0]=nf[0][5]=nf[0][10]=nf[0][15]=nf[0][20]=nf[0][25]=nf[0][30]=1;
// ntt::mul(f[0],520,nf[0],520);
// for(int i=0;i<=10;++i)printf("%d ",f[0][i]);putchar(10);
scanf("%d%d%*d",&n,&q);
for(int i=1;i<=n;++i){scanf("%d",a+i);for(int j=1;j<=a[i];++j)scanf("%d%d",b[i]+j,c[i]+j);}
for(int i=0;i<=n;++i)lg[1<<i]=i+1;
for(int i=1;i<=n;++i)
{
f[i][0]=1;
for(int j=1;j<=a[i];++j)
{
for(int _=0;_<=520;++_)nf[i][_]=0;
for(int _=0;_*b[i][j]<=520&&_<=c[i][j];++_)nf[i][_*b[i][j]]=1;
ntt::mul(f[i],520,nf[i],520);
for(int _=521;_<=2048;++_)f[i][_]=nf[i][_]=0;
}
// for(int _=0;_<=520;++_)printf("%d ",f[i][_]);putchar(10);printf("\n");
}
dp[0][0][521]=1;
for(int i=0;i<1<<n;++i)pcnt[i]=pcnt[i>>1]+(i&1);
for(int i=0;i<1<<n;++i)
{
for(int _=0;_<=520;++_)
{
prod[i][_]=1;
for(int __=1;__<=n;++__)if(i>>__-1&1)prod[i][_]=1ll*prod[i][_]*f[__][_]%p;
}
}
for(int S=0;S<1<<n;++S)
{
for(int i=0;i<=520;++i)
{
for(int las=520;~las;--las)
{
for(int T=S;T;T=T-1&S)
{
if(i>=las*pcnt[T])dp[S][i][las]+=dp[S^T][i-las*pcnt[T]][las+1]*prod[T][las]%p;
}
dp[S][i][las]+=dp[S][i][las+1];
dp[S][i][las]%=p;
sum[S][i][las]=((i?sum[S][i-1][las]:0)+dp[S][i][las])%p;
}
}
}
// for(int S=0;S<1<<n;++S)
// {
// for(int i=0;i<=20;++i)
// {
// for(int las=0;las<=20;++las)printf("S:%d i:%d las:%d dp:%lld\n",S,i,las,dp[S][i][las]);
// }
// }
while(q--)
{
int m,k;scanf("%s%d%d",s+1,&m,&k);
int S=0;for(int i=1;i<=n;++i)S|=s[i]-'0'<<i-1;
long long ans=0;
for(int _=0;_<=m;++_)ans+=sum[S][_][k]*dp[(1<<n)-1^S][m-_][0]%p;
printf("%lld\n",ans%p);
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 13ms
memory: 14240kb
input:
1 521 998244353 39 520 520 11 22 414 8 95 18 229 356 26 407 316 10 24 26 19 61 11 130 482 476 420 15 192 193 208 24 19 233 494 217 275 294 26 28 439 20 272 277 28 198 5 335 22 8 28 17 154 78 6 13 175 17 2 5 477 256 200 4 1 36 427 371 439 23 10 65 426 25 24 27 121 29 28 13 12 453 0 520 1 1 519 1 1 51...
output:
38813347 22154243 567712996 960956978 22154233 960956968 567712974 22154207 567712948 22154175 960956896 960956868 22154091 960956786 960956732 960956668 960956592 567712512 960956386 22153513 567712114 960955920 22152965 567711464 22152413 960954806 960954408 567709954 22150661 960952772 22149313 9...
result:
wrong answer 2nd lines differ - expected: '922143638', found: '22154243'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #9:
score: 0
Time Limit Exceeded
input:
15 52099 998244353 1 9 3 1 9 4 1 9 2 1 8 10 1 4 4 1 3 1 1 2 5 1 4 9 1 1 4 1 9 4 1 7 6 1 1 6 1 2 5 1 5 2 1 3 5 101000000001010 516 1 010001001010101 520 2 000000101000001 519 2 101011111100011 518 1 010110001000111 520 2 000110111100111 516 1 000100101001011 519 3 000111001010011 518 1 00001110010111...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%