QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209098#6325. Peaceful Resultsc20230201RE 522ms120312kbC++142.6kb2023-10-10 09:53:392023-10-10 09:53:39

Judging History

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

  • [2023-10-10 09:53:39]
  • 评测
  • 测评结果:RE
  • 用时:522ms
  • 内存:120312kb
  • [2023-10-10 09:53:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll maxn=3e6+5, mo=998244353;

ll A[3][3];
ll Y[6], a[6][7];

ll lcm(ll a,ll b) {
	return a*b/__gcd(a,b);
}

void Guass() {
	for(ll i=0;i<6;i++) {
		ll id=0;
		for(ll j=i;j<6;j++) if(a[j][i]) id=j;
		swap(a[id],a[i]);
		for(ll j=0;j<6;j++) {
			if(j==i) continue;
			if(a[j][i]) {
				ll t=lcm(a[i][i],a[j][i]);
				ll t1=t/a[i][i], t2=t/a[j][i];
				for(ll k=0;k<7;k++) a[i][k]*=t1, a[j][k]*=t2;
				for(ll k=0;k<7;k++) a[j][k]=a[j][k]-a[i][k];
			}
		}
	}
	for(ll i=0;i<6;i++) {
		if(a[i][6]%a[i][i]) {
			cout<<"0\n";
			exit(0);
		}
		Y[i]=a[i][6]/a[i][i];
	}
	return ;
}

const ll N=3e6;
ll rev[maxn], ta[maxn], tb[maxn], tc[maxn], fac[maxn], ifac[maxn];

ll qpow(ll a,ll p) {
	ll res=1;
	while(p) {
		if(p&1) res=res*a%mo;
		p>>=1, a=a*a%mo;
	}
	return res;
}

void NTT(ll c[maxn],ll n,ll o) {
	for(ll i=0;i<n;i++) if(rev[i]>i) swap(c[i],c[rev[i]]);
	for(ll len=1;len<n;len<<=1) {
		ll wn=qpow(3,(mo-1)/len/2);
		if(o==-1) wn=qpow(wn,mo-2); 
		for(ll l=0;l<n;l+=2*len) {
			for(ll r=l,wx=1; r<l+len; r++,wx=wx*wn%mo) {
				ll x=c[r], y=wx*c[r+len]%mo;
				c[r]=(x+y)%mo, c[r+len]=(x-y+mo)%mo;
			}
		}
	}
	if(o==-1) {
		ll inv=qpow(n,mo-2)%mo;
		for(ll i=0;i<n;i++) c[i]=c[i]*inv%mo;
	}
	return ;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	fac[0]=1;
	for(ll i=1;i<=N;i++) fac[i]=fac[i-1]*i%mo;
	ifac[N]=qpow(fac[N],mo-2);
	for(ll i=N-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mo;
	ll n; cin>>n;
	for(ll i=0;i<3;i++) {
		for(ll j=0;j<3;j++) {
			cin>>A[i][j];
		}
	}
	a[0][0]=a[0][2]=a[0][4]=1;
	a[0][6]=A[0][0]-A[0][2];
	a[1][1]=a[1][3]=a[1][5]=1;
	a[1][6]=A[0][1]-A[0][2];
	a[2][0]=a[2][3]=1, a[2][2]=a[2][5]=-1;
	a[2][6]=A[1][0]-A[1][2];
	a[3][1]=a[3][4]=1, a[3][2]=a[3][5]=-1;
	a[3][6]=A[1][1]-A[1][2];
	a[4][0]=a[4][5]=1, a[4][3]=a[4][4]=-1;
	a[4][6]=A[2][0]-A[2][2];
	a[5][1]=a[5][2]=1, a[5][3]=a[5][4]=-1;
	a[5][6]=A[2][1]-A[2][2];
	Guass();
	ll nn=n;
	n=A[0][2];
	ll l1=max(-Y[0],-Y[1]), l2=max(-Y[2],-Y[3]), l3=max(-Y[4],-Y[5]);
	l1=max(0ll,l1), l2=max(0ll,l2), l3=max(0ll,l3);
	ll len=1, px=0;
	while(len<=3*n) len<<=1, px++;
	for(ll i=1;i<len;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<px-1);
	for(ll i=l1;i<=n;i++) ta[i]=ifac[i]*ifac[i+Y[0]]%mo*ifac[i+Y[1]]%mo;
	for(ll i=l2;i<=n;i++) tb[i]=ifac[i]*ifac[i+Y[2]]%mo*ifac[i+Y[3]]%mo;
	for(ll i=l3;i<=n;i++) tc[i]=ifac[i]*ifac[i+Y[4]]%mo*ifac[i+Y[5]]%mo;
	NTT(ta,len,1), NTT(tb,len,1), NTT(tc,len,1);
	for(ll i=0;i<len;i++) ta[i]=ta[i]*tb[i]%mo*tc[i]%mo;
	NTT(ta,len,-1);
	cout<<ta[n]*fac[nn]%mo<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 27ms
memory: 55032kb

input:

2
2 0 0
1 1 0
1 0 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 27ms
memory: 51136kb

input:

3
0 1 2
3 0 0
1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 148ms
memory: 69632kb

input:

333333
111111 111111 111111
111111 111111 111111
111111 111111 111111

output:

383902959

result:

ok 1 number(s): "383902959"

Test #4:

score: 0
Accepted
time: 514ms
memory: 119180kb

input:

1500000
500000 500000 500000
500000 500000 500000
500000 500000 500000

output:

355543262

result:

ok 1 number(s): "355543262"

Test #5:

score: 0
Accepted
time: 522ms
memory: 120312kb

input:

1499999
499999 499999 500001
499999 499999 500001
499999 499999 500001

output:

934301164

result:

ok 1 number(s): "934301164"

Test #6:

score: -100
Runtime Error

input:

1500000
1 0 1499999
1499999 1 0
0 1499999 1

output:


result: