QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#66750#5169. 夹娃娃leaf_normal0 1221ms6444kbC++142.6kb2022-12-09 11:35:102022-12-09 11:35:11

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:35:11]
  • 评测
  • 测评结果:0
  • 用时:1221ms
  • 内存:6444kb
  • [2022-12-09 11:35:10]
  • 提交

answer

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define LL long long
#define mo 998244353
#define N 1200005
#define ad(x,y) x+=y,x-=(x>=mo?mo:0)
using namespace std;
int read()
{
	int x=0,x1=0;char ch=getchar();
	while(!isdigit(ch))x1|=(ch=='-'),ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return (x1?-x:x);
}
int r[N];
LL ksm(LL x,int y)
{
	if(!y)return 1;
	LL z=ksm(x,y>>1);
	return((y&1)?z*z%mo*x%mo:z*z%mo);
}
struct poly{
	vector<int> a;
	void ntt(int x,int inv)
	{
		fo(i,0,x)r[i]=(i&1)*(x>>1)+(r[i>>1]>>1);
		fo(i,0,x-1)if(i>r[i])swap(a[i],a[r[i]]);
		for(int len=2;len<=x;len<<=1)
		{
			LL mi=len>>1,zqr=ksm(3,(mo-1)/len);
			if(inv<0)zqr=ksm(zqr,mo-2);
			for(int wz=0;wz<x;wz+=len)
			{ 
				LL zq=1;
				fo(k,1,mi)
				{
					LL ji=1ll*a[wz+mi+k-1]*zq%mo;
					a[wz+mi+k-1]=a[wz+k-1]-ji;
					a[wz+mi+k-1]+=(a[wz+mi+k-1]<0?mo:0);
					a[wz+k-1]+=ji;
					a[wz+k-1]-=(a[wz+k-1]>=mo?mo:0);
					zq=1ll*zq*zqr%mo;
				}
			}
		}
		if(inv<0)
		{
			LL nm=ksm(x,mo-2);
			fo(i,0,x-1)a[i]=1ll*a[i]*nm%mo;
		}
	}
	void res(int x)
	{
		a.resize(x);
	}
	friend poly operator *(poly A,poly B)
	{
		int x=1,tp=A.a.size()+B.a.size()-1;
		while(x<tp)x<<=1;
		A.res(x),B.res(x);
		A.ntt(x,1);B.ntt(x,1);
		fo(i,0,x-1)A.a[i]=1ll*A.a[i]*B.a[i]%mo;
		A.ntt(x,-1);
		A.res(tp);
		return A;
	}
};
int n,mid;
poly an[16],an1[525][33],an2[525][33];
bool vis1[525][33],vis2[525][33];
void cal1(int k,int zt)
{
	poly ans;
	fo(i,1,mid)
	{
		poly b=an[i];
		if(zt&(1<<i-1))fo(j,0,k-1)b.a[j]=0;
		if(ans.a.empty())ans=b;
		else ans=ans*b,ans.res(521); 
	}
	vis1[k][zt]=1;an1[k][zt]=ans;
}
void cal2(int k,int zt)
{
	poly ans;ans.a={1};
	fo(i,mid+1,n)
	{
		poly b=an[i];
		if(zt&(1<<i-mid-1))fo(j,0,k-1)b.a[j]=0;
		if(ans.a.empty())ans=b;
		else ans=ans*b,ans.res(521); 
	}
	vis2[k][zt]=1;an2[k][zt]=ans;
}
int main()
{
	n=read();mid=n>>1;
	int q=read();read();
	fo(i,1,n)
	{
		poly f;
		f.a={1};
		int nu=read();
		fo(j,1,nu)
		{
			int x=read(),y=read();
			poly a;a.res(521);
			fo(j,0,520)if(j/x<=y&&j%x==0)a.a[j]=1;
			else a.a[j]=0;
			f=f*a;
			f.res(521);
		}
		an[i]=f;
	}
	while(q--)
	{
		char c[20];scanf("%s",c+1);
		int m=read(),k=read(),zt1=0,zt2=0;
		fo(i,1,mid)zt1|=(1<<i-1)*(c[i]^48);
		if(!vis1[k][zt1])cal1(k,zt1);
		fo(i,mid+1,n)zt2|=(1<<i-mid-1)*(c[i]^48);
		if(!vis2[k][zt2])cal2(k,zt2);
		int ans=0,su=0;
		fo(i,0,m)ad(su,an1[k][zt1].a[i]),ad(ans,1ll*su*an2[k][zt2].a[m-i]%mo);
		printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

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:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 1221ms
memory: 6444kb

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
932306470
461733882
308912117
271186941
496689529
919511294
228090352
48...

result:

wrong answer 24th lines differ - expected: '493445999', found: '932306470'

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%