QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#66658 | #5169. 夹娃娃 | hjl666 | 3 | 1485ms | 5908kb | C++14 | 3.7kb | 2022-12-09 10:28:43 | 2022-12-09 10:28:46 |
Judging History
answer
#include<bits/stdc++.h>
#define db double
//#define int ll
#define ll long long
#define ull unsigned long long
#define pb emplace_back
#define MP make_pair
#define pii pair<int, int>
#define fi first
#define se second
#define ls k<<1
#define rs k<<1|1
#define lowbit(i) (i&(-i))
#define CLK (double)clock()/(double)CLOCKS_PER_SEC
using namespace std;
mt19937 rnd(time(0));
inline int read(){
register int x=0,f=1;
register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void write(register int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
const int N=2050,mod=998244353,G=3;
int rev[N];
inline int Qpow(int b,int p){
int res=1;
while(p){
if(p&1)res=1ll*res*b%mod;
b=1ll*b*b%mod;p>>=1;
}
return res;
}
inline void change(int *y,int n){
for(int i=0;i<n;i++){
rev[i]=rev[i>>1]>>1;
if(i&1)rev[i]|=(n>>1);
}
for(int i=0;i<n;i++){
if(i<rev[i])swap(y[i],y[rev[i]]);
}
}
inline void NTT(int *y,int n,int on){
change(y,n);
for(int h=2;h<=n;h<<=1){
int gn=Qpow(G,(mod-1)/h);
if(on==-1)gn=Qpow(gn,mod-2);
for(int j=0;j<n;j+=h){
int g=1;
for(int k=j;k<j+h/2;k++){
ll u=y[k],t=1ll*g*y[k+h/2]%mod;
y[k]=(u+t)%mod,y[k+h/2]=(u-t+mod)%mod;
g=1ll*g*gn%mod;
}
}
}
if(on==1)return ;
int ivn=Qpow(n,mod-2);
for(int i=0;i<n;i++)y[i]=1ll*y[i]*ivn%mod;
}
int n,q,p,len,a[20],b[20][N],c[20][N],A[N],B[20][N],C[N],D[N],pre[1<<15][N];
char s[53000][20];
int m[53000],k[53000];
void prework(int i,int j,int *a){
memset(A,0,sizeof A);
for(int k=0;k<=c[i][j]&&k*b[i][j]<=520;k++)a[k*b[i][j]]=1;
}
void work(int *C,int *A,int *B){
NTT(A,len,1);NTT(B,len,1);
for(int j=0;j<len;j++)C[j]=1ll*A[j]*B[j]%mod;
NTT(A,len,-1);NTT(B,len,-1);
NTT(C,len,-1);for(int j=521;j<len;j++)C[j]=0;
}
void MAIN(){
n=read();q=read();p=read();len=N-2;//while(len<=N)len<<=1;
for(int i=1;i<=n;i++){
a[i]=read();
for(int j=1;j<=a[i];j++)b[i][j]=read(),c[i][j]=read();
}
for(int i=1;i<=q;i++)scanf("%s",s[i]+1),m[i]=read(),k[i]=read();
for(int id=1;id<=n;id++){
B[id][0]=1;
for(int i=1;i<=a[id];i++){
prework(id,i,A);NTT(A,len,1);NTT(B[id],len,1);
for(int j=0;j<len;j++)B[id][j]=1ll*B[id][j]*A[j]%mod;
NTT(B[id],len,-1);for(int j=521;j<len;j++)B[id][j]=0;
}
// for(int j=0;j<10;j++)cout<<B[id][j]<<' ';cout<<"\n";
memcpy(pre[1<<(id-1)],B[id],sizeof B[id]);
}
// for(int i=0;i<=520;i++)cout<<B[1][i]<<' ';cout<<"\n";
int tot=(1<<n)-1;
if(n<=2){
for(int S=0;S<=tot;S++){
if(S==0){pre[S][0]=1;continue;}
// cout<<S<<' '<<lowbit(S)<<"\n";
if(S!=lowbit(S))work(pre[S],pre[S^lowbit(S)],pre[lowbit(S)]);
// for(int j=0;j<10;j++)cout<<pre[S][j]<<' ';cout<<"\n";
}
}
for(int _=1;_<=q;_++){
int S=0;
for(int id=1;id<=n;id++)if(s[_][id]=='0')S|=1<<(id-1);
memcpy(D,pre[S],sizeof pre[S]);
// for(int j=0;j<10;j++)cout<<D[j]<<' ';cout<<"\n";
for(int id=1;id<=n;id++){
if(s[_][id]=='0')continue;
for(int j=0;j<len;j++)C[j]=B[id][j];
for(int j=0;j<k[_];j++)C[j]=0;
NTT(C,len,1);NTT(D,len,1);
for(int j=0;j<len;j++)D[j]=1ll*D[j]*C[j]%mod;
NTT(D,len,-1);for(int j=521;j<len;j++)D[j]=0;
}
int res=0;
for(int i=0;i<=m[_];i++)(res+=D[i])%=mod;
// for(int i=0;i<=m[_];i++)if(D[i])cout<<i<<' '<<D[i]<<"\n";
cout<<res<<"\n";
}
}
signed main(){
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
int T=1;while(T--)MAIN();
// printf("\nTIME:%lf\n",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 107ms
memory: 5692kb
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 922143638 98254957 38813343 922143633 38813338 98254946 922143620 98254933 922143604 38813302 38813288 922143562 38813247 38813220 38813188 38813150 98254715 38813047 922143273 98254516 38812814 922142999 98254191 922142723 38812257 38812058 98253436 922141847 38811240 922141173 38810463 38...
result:
ok 521 lines
Test #2:
score: 0
Accepted
time: 546ms
memory: 3904kb
input:
2 1561 998244353 151 520 520 511 30 121 396 25 16 113 11 6 175 242 20 8 5 61 13 518 447 404 8 220 177 4 19 18 15 70 233 9 14 26 512 17 9 9 19 30 8 495 20 13 27 277 22 396 14 4 29 345 442 19 25 14 5 16 295 19 65 134 10 10 296 245 6 7 30 253 15 187 26 482 454 28 414 170 404 11 27 27 25 13 509 1 5 291 ...
output:
883965618 144348435 762074635 112296779 385763651 821718611 673974966 879750066 927942969 136450507 436584627 612945970 768262217 613885343 39304132 852224740 215596261 151746110 965953558 969833936 664053020 458247365 881060255 878484499 781573019 616944059 850325449 296113117 674829177 887392623 6...
result:
ok 1561 lines
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #3:
score: 0
Wrong Answer
time: 1485ms
memory: 5908kb
input:
3 4160 998244353 444 520 520 26 332 29 183 25 479 175 14 13 16 1 447 2 293 4 20 64 472 491 11 21 259 75 22 390 401 8 508 405 3 137 4 15 154 164 1 484 13 257 14 44 20 7 13 26 15 26 432 14 9 478 24 18 10 22 28 8 21 260 25 431 22 7 6 20 26 8 27 239 19 1 134 2 322 16 225 6 42 517 6 197 407 268 500 433 5...
output:
0 0 0 345860798 0 577475723 191997503 0 0 0 0 514747110 0 92531482 136793394 0 0 0 0 569418540 0 844207347 78271439 0 0 0 0 634787992 0 893938722 980664180 0 0 0 0 671706573 0 553976298 397022403 0 0 0 0 914377223 0 368899075 203123707 0 0 0 0 355688626 0 862480118 668082658 0 0 0 0 99785336 0 21579...
result:
wrong answer 1st lines differ - expected: '516056999', found: '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%