QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782584#5530. No Zero-Sum SubsegmentSymbolizeWA 21ms34968kbC++171.7kb2024-11-25 20:33:332024-11-25 20:33:34

Judging History

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

  • [2024-11-25 20:33:34]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:34968kb
  • [2024-11-25 20:33:33]
  • 提交

answer

/*
	Luogu name: Symbolize
	Luogu uid: 672793
*/
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define rep1(i,l,r) for(register int i=l;i<=r;++i)
#define rep2(i,l,r) for(register int i=l;i>=r;--i)
#define rep3(i,x,y,z) for(register int i=x[y];~i;i=z[i])
#define rep4(i,x) for(auto i:x)
#define debug() puts("----------")
const int N=4e6+10;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
using namespace std;
int t,prod[N],a,b,c,d;
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return f*x;
}
int power(int a,int b,int p)
{
	int ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ans;
}
int C(int n,int m)
{
	if(n<m) return 0;
	return prod[n]*power(prod[m],mod-2,mod)%mod*power(prod[n-m],mod-2,mod)%mod;
}
int calc(int b,int c,int d)
{
	if(d<2*b) return 0;
	return C(c+d-2*b+b,b)*C(c+d-2*b+b-b,c)%mod;
}
void getans()
{
	a=read();
	b=read();
	c=read();
	d=read();
	int x=-2*a-b+c+2*d;
	if(x==0)
	{
		puts("0");
		return;
	}
	if(x<0) swap(a,d),swap(b,c);
	cout<<(
			calc(b-2,c,d-a-2)*(a+1)			%mod
		+	calc(b-1,c-1,d-a-1)*a*2			%mod
		+	calc(b,c-2,d-a)*(bool)(a)*(a-1)	%mod
		+	calc(b,c-1,d-a)*(bool)(a)*2		%mod
		+	calc(b-1,c,d-a-1)*2				%mod
		+	calc(b,c,d)*(bool)(!a)			%mod
		)%mod<<"\n";
	return;
}
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	prod[0]=1;
	rep1(i,1,4e6) prod[i]=prod[i-1]*i%mod;
	t=read();
	while(t--) getans();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 21ms
memory: 34968kb

input:

5
69 0 0 0
1 1 1 1
0 0 3 3
6 1 0 6
10000 10000 1000000 1000000

output:

1
0
20
332748122
480402900

result:

wrong answer 4th numbers differ - expected: '2', found: '332748122'