QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358956#6325. Peaceful Results275307894aWA 469ms207652kbC++143.6kb2024-03-20 09:51:522024-03-20 09:51:52

Judging History

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

  • [2024-03-20 09:51:52]
  • 评测
  • 测评结果:WA
  • 用时:469ms
  • 内存:207652kb
  • [2024-03-20 09:51:52]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1.5e6+5,M=(1<<22)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,Ar,Ap,As,Br,Bp,Bs,Cr,Cp,Cs;
ll frc[N],inv[N],A[M],B[M],C[M];

int k;
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
namespace poly{
	int tr[M];ll pw[M];const int g=3,Ig=mpow(g);
	void init(int n){
		k=0;for(k=1;k<=n;k<<=1);
		for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|((i&1)?k/2:0);
		ll w=mpow(g,(mod-1)/k);
		pw[k/2]=1;for(int i=k/2+1;i<k;i++) pw[i]=pw[i-1]*w%mod;
		for(int i=k/2-1;i;i--) pw[i]=pw[i<<1];
	}
	void NTT(ll *A,int k,int flag){
		static ull a[M];
		int i,j,h;for(int i=0;i<k;i++) a[tr[i]]=A[i];
		for(int i=2;i<=k;i<<=1){
			ll *e=pw+i/2;
			for(int j=0;j<k;j+=i){
				for(int h=j;h<j+i/2;h++) {
					ll now=e[h-j]*a[h+i/2]%mod;
					a[h+i/2]=a[h]+mod-now;
					a[h]+=now;
				}
			}
			if(i==(1<<18)){for(int j=0;j<k;j++) a[j]%=mod;}
		}
		for(int i=0;i<k;i++) A[i]=a[i]%mod;
		if(flag) return;
		ll iv=mpow(k);for(int i=0;i<k;i++) A[i]=A[i]*iv%mod;
		reverse(A+1,A+k);
	}
}

void convolute(ll *A,ll *B,ll *C){
	poly::init(2*(n+1));
	poly::NTT(A,k,1);poly::NTT(B,k,1);
	for(int i=0;i<k;i++) C[i]=A[i]*B[i]%mod;
	poly::NTT(C,k,0);
	// for(int i=0;i<=n;i++) if(A[i]) for(int j=0;j<=n;j++) if(B[j]) C[i+j]=(C[i+j]+A[i]*B[j])%mod;
}

void Solve(){
	int i,j;scanf("%d%d%d%d%d%d%d%d%d%d",&n,&Ar,&Ap,&As,&Br,&Bp,&Bs,&Cr,&Cp,&Cs);
	inv[1]=1;for(i=2;i<=n;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
	for(inv[0]=frc[0]=i=1;i<=n;i++) inv[i]=inv[i-1]*inv[i]%mod,frc[i]=frc[i-1]*i%mod;
	ll ans=0;
	for(int x1=0;x1<=n;x1++){
		if(x1>Ar||x1>Br||x1>Cr) continue;
		int x4=Ar+Br+Cr-3*x1-Ap-Bp-Cp;
		if(x4%3) continue;x4/=-3;
		if(x4<0||x4>Ap||x4>Bp||x4>Cp) continue;
		int x7=Ar+Br+Cr-3*x1-As-Bs-Cs;
		if(x7%3) continue;x7/=-3;
		if(x7<0||x7>As||x7>Bs||x7>Cs) continue;
		A[x1]=inv[x1]*inv[x4]%mod*inv[x7]%mod;
	}
	for(int x2=0;x2<=n;x2++){
		if(x2>Ar||x2>Bp||x2>Cs) continue;
		int x5=Ar+Bp+Cs-3*x2-Ap-Bs-Cr;
		if(x5%3) continue;x5/=-3;
		if(x5<0||x5>Ap||x5>Bs||x5>Cr) continue;
		int x8=Ar+Bp+Cs-3*x2-As-Br-Cp;
		if(x8%3) continue;x8/=-3;
		if(x8<0||x8>As||x8>Bp||x8>Cr) continue;
		B[x2]=inv[x2]*inv[x5]%mod*inv[x8]%mod;
	}
	convolute(A,B,C);
	for(int xs=0;xs<=2*n;xs++){
		int x3=Ar-xs;
		if(x3<0||x3>Ar||x3>Bs||x3>Cp) continue;
		int x6=Ar+Bs+Cp-3*x3-Ap-Br-Cs;
		if(x6%3) continue;x6/=-3;
		if(x6<0||x6>Ap||x6>Br||x6>Cs) continue;
		int x9=Ar+Bs+Cp-3*x3-As-Bp-Cr;
		if(x9%3) continue;x9/=-3;
		if(x9<0||x9>As||x9>Bp||x9>Cr) continue;
		ans+=C[xs]*inv[x3]%mod*inv[x6]%mod*inv[x9]%mod;
	}
	printf("%lld\n",ans%mod*frc[n]%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8148kb

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: 1ms
memory: 6060kb

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: 76ms
memory: 56160kb

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: 469ms
memory: 207652kb

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: 447ms
memory: 207648kb

input:

1499999
499999 499999 500001
499999 499999 500001
499999 499999 500001

output:

934301164

result:

ok 1 number(s): "934301164"

Test #6:

score: -100
Wrong Answer
time: 463ms
memory: 207640kb

input:

1500000
1 0 1499999
1499999 1 0
0 1499999 1

output:

0

result:

wrong answer 1st numbers differ - expected: '1500000', found: '0'