QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#66713#5169. 夹娃娃aoui3 351ms20616kbC++142.3kb2022-12-09 11:12:312022-12-09 11:12:33

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:12:33]
  • 评测
  • 测评结果:3
  • 用时:351ms
  • 内存:20616kb
  • [2022-12-09 11:12:31]
  • 提交

answer

#include<cstdio>
#include<algorithm>
using namespace std;
#include<cstring>
#define ll long long
#define ull unsigned long long
#include<vector>
#define Poly vector<int>
#define cpy(a,b,n) memcpy(a,b,sizeof(int)*(n))
#define clr(a,n) memset(a,0,sizeof(int)*(n))
const int mo=998244353,_G=3,maxn=1<<18|500;
ll fpow(ll x,ll y=mo-2)
{
	ll res=1;
	for(;y;y>>=1,x=x*x%mo)if(y&1)res=res*x%mo;
	return res;
}
const int invG=fpow(_G);
int re[maxn<<1],rfl=0,lim=521,_inv[maxn],nn=2048;
void Rev(int n)
{
	if(rfl==n)return;
	rfl=n;
	for(int i=0;i<n;i++)re[i]=(re[i>>1]>>1)|((i&1)?n>>1:0);
}
void NTT(int *g,bool op,int n)
{
	Rev(n);
	static ull f[maxn<<1],_w[maxn<<1];
	_w[0]=1;
	for(int i=0;i<n;i++)f[i]=(((ll)mo<<5)+g[re[i]])%mo;
	for(int l=1;l<n;l<<=1)
	{
		ull _g=fpow(op?_G:invG,(mo-1)/(l+l));
		for(int i=1;i<l;i++)_w[i]=_w[i-1]*_g%mo;
		for(int k=0;k<n;k+=l+l)
			for(int j=0;j<l;j++)
			{
				int _t=_w[j]*f[l|k|j]%mo;
				f[l|k|j]=f[k|j]+mo-_t;
				f[k|j]+=_t;
			}
		if(l==(1<<10))for(int i=0;i<n;i++)f[i]%=mo;
	}
	if(!op)
	{
		ull invn=fpow(n);
		for(int i=0;i<n;i++)g[i]=f[i]%mo*invn%mo;
	}
	else for(int i=0;i<n;i++)g[i]=f[i]%mo;
}
const int N=16,M=2.1e3+5;
int n,Q,s[N][522][M],t[M],f[M],g[M];
char ch[N];
int main()
{
	int id;
	scanf("%d%d%d",&n,&Q,&id);
	for(int i=1;i<=n;i++)
	{
		int k;
		scanf("%d",&k);
		for(int j=0;j<nn;j++)f[j]=1;
		for(;k;k--)
		{
			int a,b;
			scanf("%d%d",&a,&b);
			for(int j=0;j<nn;j++)g[j]=0;
			for(int j=0;j<=b&&a*j<nn/2;j++)g[j*a]=1;
			NTT(g,1,nn);
			for(int j=0;j<nn;j++)f[j]=1ll*f[j]*g[j]%mo;
			NTT(f,0,nn);
			for(int j=nn/2;j<nn;j++)f[j]=0;
			NTT(f,1,nn);
		}
		NTT(f,0,nn);
		for(int j=nn/2;j<nn;j++)f[j]=0;
		for(int j=0;j<=520;j++)
		{
			for(int l=0;l<nn/2;l++)s[i][j][l]=f[l];
			NTT(s[i][j],1,nn);
			f[j]=0;
		}
	}
	for(;Q;Q--)
	{
		for(int i=0;i<nn;i++)t[i]=1;
		char cc=getchar();
		scanf("%s",ch+1);
		int m,k;
		scanf("%d%d",&m,&k);
		for(int i=1;i<=n;i++)
		{
			if(ch[i]=='1')
				for(int j=0;j<nn;j++)t[j]=1ll*t[j]*s[i][k][j]%mo;
			else
				for(int j=0;j<nn;j++)t[j]=1ll*t[j]*s[i][0][j]%mo;
//			NTT(t,0,nn);
//			for(int j=nn/2;j<nn;j++)t[j]=0;
//			NTT(t,1,nn);
		}
		NTT(t,0,nn);
		int ans=0;
		for(int i=0;i<=m;i++)ans=(ans+t[i])%mo;
		printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 41ms
memory: 12808kb

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: 202ms
memory: 16272kb

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: 351ms
memory: 20616kb

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:

924091220
443637624
905082519
753895019
309117938
477467863
643783330
941659982
924091220
317156179
105859558
922781331
711592368
544317309
544827615
626131809
252545535
570885585
823190689
502442491
150740456
442299798
518262530
678104973
924091220
621402353
965216671
326218015
554460319
269569706
...

result:

wrong answer 1st lines differ - expected: '516056999', found: '924091220'

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:

993379058
496689529
866368587
797687294
481245176
481245176
39022588
269889529
552778235
769822588
331666941
99789529
903956470
112750588
756797435
519045176
870912000
361582588
594280447
494747647
597778941
178845176
435456000
493445999
461733882
308912117
271186941
496689529
919511294
85533882
894...

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%