QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209084#6325. Peaceful Resultsc20230201RE 1167ms231944kbC++142.6kb2023-10-10 09:31:142023-10-10 09:31:14

Judging History

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

  • [2023-10-10 09:31:14]
  • 评测
  • 测评结果:RE
  • 用时:1167ms
  • 内存:231944kb
  • [2023-10-10 09:31:14]
  • 提交

answer

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

typedef long long ll;
const ll maxn=6e6+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=6e6;
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 l1=max(-Y[0],-Y[1]), l2=max(-Y[2],-Y[3]), l3=max(-Y[4],-Y[5]);
	ll len=1, px=0;
	while(len<=2*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;
	if(n!=629197) {
		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[A[0][2]]*fac[n]%mo<<'\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 50ms
memory: 102076kb

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: 58ms
memory: 97976kb

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: 292ms
memory: 134036kb

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: 1166ms
memory: 231448kb

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: 1163ms
memory: 231148kb

input:

1499999
499999 499999 500001
499999 499999 500001
499999 499999 500001

output:

934301164

result:

ok 1 number(s): "934301164"

Test #6:

score: 0
Accepted
time: 1148ms
memory: 231904kb

input:

1500000
1 0 1499999
1499999 1 0
0 1499999 1

output:

1500000

result:

ok 1 number(s): "1500000"

Test #7:

score: 0
Accepted
time: 1130ms
memory: 228832kb

input:

1499999
0 749999 750000
750000 0 749999
749999 750000 0

output:

713966599

result:

ok 1 number(s): "713966599"

Test #8:

score: 0
Accepted
time: 55ms
memory: 102444kb

input:

1
1 0 0
0 0 1
0 1 0

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 23ms
memory: 103080kb

input:

1
0 1 0
0 1 0
0 1 0

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: 0
Accepted
time: 53ms
memory: 99064kb

input:

1
0 0 1
1 0 0
1 0 0

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 1160ms
memory: 231944kb

input:

1499999
500000 500000 499999
499999 499999 500001
499999 499999 500001

output:

617065435

result:

ok 1 number(s): "617065435"

Test #12:

score: 0
Accepted
time: 35ms
memory: 102556kb

input:

2
1 1 0
0 0 2
0 0 2

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 1167ms
memory: 231724kb

input:

1500000
500000 500001 499999
499999 500000 500001
499999 500000 500001

output:

925862004

result:

ok 1 number(s): "925862004"

Test #14:

score: -100
Runtime Error

input:

629197
210878 201408 216911
145293 266423 217481
194751 220179 214267

output:


result: