QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#66721#5169. 夹娃娃skicean0 380ms3708kbC++143.0kb2022-12-09 11:16:382022-12-09 11:16:40

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-09 11:16:40]
  • 评测
  • 测评结果:0
  • 用时:380ms
  • 内存:3708kb
  • [2022-12-09 11:16:38]
  • 提交

answer

#include <cstdio>
#include <iostream>
#define macro_expand(x) #x
#define print_macro(x) printf("%s\n",macro_expand(x))
#define FOR(i,l,r) for(int i=(l),i##ADJK=(r);i<=i##ADJK;++i)
#define ROF(i,r,l) for(int i=(r),i##ADJK=(l);i>=i##ADJK;--i)
using namespace std;
typedef long long LL;
namespace work1{
	const int MN=20,Mod=998244353,len=2048;
	int N,q,UIJF,poly[MN][525],p2[MN][525],A[len+5],B[len+5],rev[len+5],g[20],ig[20];
	int ad(int x,int y){
		static int moji;
		moji=x+y;
		return (moji>=Mod)?(moji-Mod):moji;
	}
	int dc(int x,int y){
		static int moji;
		moji=x-y;
		return (moji<0)?(moji+Mod):moji;
	}
	int ml(int x,int y){return (LL)x*y%Mod;}
	int add(int &x,int y){return ((x+=y)>=Mod)?(x-=Mod):x;}
	int dec(int &x,int y){return ((x-=y)<0)?(x+=Mod):x;}
	int ksm(int x,int y){
		int ret=1;
		for(;y;y>>=1,x=ml(x,x))
			if(y&1)
				ret=ml(ret,x);
		return ret;
	}
	void init(){
		FOR(i,1,len-1)rev[i]=(rev[i>>1]>>1)|((i&1)?(len>>1):0);
		FOR(i,0,11)g[i]=ksm(3,(Mod-1)>>i);
		FOR(i,0,11)ig[i]=ksm(g[i],Mod-2);
	}
	void ntt(int *a,int type){
		FOR(i,0,len-1)if(i<rev[i])swap(a[i],a[rev[i]]);
		int cnt=1;
		for(int l=2;l<=len;l<<=1){
			int w=(type>0)?g[cnt]:ig[cnt];
			++cnt;
			for(int b=0;b<len;b+=l){
				int wn=1;
				FOR(i,b,b+(l>>1)-1){
					int x=a[i],y=ml(a[i+(l>>1)],wn);
					a[i]=ad(x,y);
					a[i+(l>>1)]=dc(x,y);
					wn=ml(wn,w);
				}
			}
		}
		if(type==-1){
			int inv=ksm(len,Mod-2);
			FOR(i,0,len-1)a[i]=ml(a[i],inv);
		}
	}
	void mul(){
		ntt(A,1),ntt(B,1);
		FOR(i,0,len-1)A[i]=ml(A[i],B[i]);
		ntt(A,-1);
		// FOR(i,0,10)cerr<<A[i]<<" ";
		// cerr<<endl;
		// FOR(i,0,10)cerr<<B[i]<<" ";
		// cerr<<endl;
	}
	int ling[1<<15][525];
	void main(){
		init();
		scanf("%d%d%d",&N,&q,&UIJF);
		FOR(i,1,N){
			int a=0;scanf("%d",&a);
			poly[i][0]=1;
			FOR(j,1,a){
				int b=0,c=0;scanf("%d%d",&b,&c);
				c=min(c,520/b);
				if(c<=15){
					ROF(x,520,0)FOR(d,1,c)add(poly[i][x],poly[i][x-d*b]);
				}else{
					FOR(x,0,520)A[x]=poly[i][x];
					FOR(x,521,len-1)A[x]=0;
					FOR(x,0,len-1)B[x]=0;
					FOR(x,0,c)B[x*b]=1;
					mul();
					FOR(x,0,520)poly[i][x]=A[x];
				}
			}
			// FOR(j,0,20)cerr<<poly[i][j]<<" ";
			// cerr<<endl;
		}
		static int wei[1<<15];
		FOR(i,0,N-1)wei[1<<i]=i;
		ling[0][0]=1;
		FOR(i,1,(1<<N)-1){
			int t=i&(-i);
			FOR(j,0,520)A[j]=ling[i^t][j];
			FOR(j,521,len-1)A[j]=0;
			FOR(j,0,520)B[j]=poly[wei[t]+1][j];
			FOR(j,521,len-1)B[j]=0;
			mul();
			FOR(j,0,520)ling[i][j]=A[j];
		}
		while(q--){
			static char str[20];
			scanf("%s",str);
			int m=0,k=0;scanf("%d%d",&m,&k);
			int st=0;
			FOR(i,0,N-1)if(str[i]=='0')st+=(1<<i);
			FOR(i,0,520)A[i]=ling[st][i];
			FOR(i,521,len-1)A[i]=0;
			FOR(i,0,N-1){
				if(str[i]=='1'){
					FOR(ji,0,k-1)B[ji]=0;
					FOR(ji,k,520)B[ji]=poly[i+1][ji];
					FOR(ji,521,len-1)B[ji]=0;
					mul();
					FOR(ji,521,len-1)A[ji]=0;
				}
			}
			int ans=0;
			FOR(i,0,m)add(ans,A[i]);
			printf("%d\n",ans);
		}
	}
}
int main(){
	work1::main();
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 89ms
memory: 3708kb

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: -3
Wrong Answer
time: 380ms
memory: 3640kb

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:

474313713
431666249
382586052
935156298
388693650
638221443
155446552
544647005
580033590
156648490
705964593
194150633
145429792
663919534
746075732
206937451
113898202
734202663
437369500
84567675
906149483
699523942
17434573
501883992
269216455
236866717
668799670
771729413
927914336
82373247
513...

result:

wrong answer 1st lines differ - expected: '883965618', found: '474313713'

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%