QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209085#6325. Peaceful Resultsc20230201WA 1127ms232592kbC++142.6kb2023-10-10 09:32:062023-10-10 09:32:06

Judging History

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

  • [2023-10-10 09:32:06]
  • 评测
  • 测评结果:WA
  • 用时:1127ms
  • 内存:232592kb
  • [2023-10-10 09:32:06]
  • 提交

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]);
	l1=max(0ll,l1), l2=max(0ll,l2), l3=max(0ll,l3);
	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;
	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: 19ms
memory: 102064kb

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: 98140kb

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: 294ms
memory: 134512kb

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: 1116ms
memory: 232592kb

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: 1104ms
memory: 231372kb

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: 1090ms
memory: 229168kb

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: 1120ms
memory: 231624kb

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: 31ms
memory: 102404kb

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: 54ms
memory: 102048kb

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: 38ms
memory: 98764kb

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: 1125ms
memory: 231932kb

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

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: 1127ms
memory: 232144kb

input:

1500000
500000 500001 499999
499999 500000 500001
499999 500000 500001

output:

925862004

result:

ok 1 number(s): "925862004"

Test #14:

score: 0
Accepted
time: 554ms
memory: 166900kb

input:

629197
210878 201408 216911
145293 266423 217481
194751 220179 214267

output:

447295633

result:

ok 1 number(s): "447295633"

Test #15:

score: 0
Accepted
time: 518ms
memory: 166480kb

input:

579097
200209 204257 174631
149110 148890 281097
138034 263752 177311

output:

71830925

result:

ok 1 number(s): "71830925"

Test #16:

score: 0
Accepted
time: 251ms
memory: 133444kb

input:

354224
100316 63899 190009
69306 123829 161089
140523 76088 137613

output:

44852283

result:

ok 1 number(s): "44852283"

Test #17:

score: 0
Accepted
time: 1101ms
memory: 229172kb

input:

1229851
383009 323934 522908
551226 311238 367387
547622 353128 329101

output:

39721313

result:

ok 1 number(s): "39721313"

Test #18:

score: -100
Wrong Answer
time: 557ms
memory: 165788kb

input:

858452
195309 312080 351063
384805 51797 421850
200466 301164 356822

output:

164751217

result:

wrong answer 1st numbers differ - expected: '506491992', found: '164751217'