QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430280#6325. Peaceful Resultsdo_while_trueTL 0ms0kbC++204.6kb2024-06-03 17:13:012024-06-03 17:13:01

Judging History

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

  • [2024-06-03 17:13:01]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-06-03 17:13:01]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
const int N=2000010;
namespace MyPoly{
	int *getw(int n, int type) {
		static int w[N/2];
		w[0]=1;w[1]=qpow(type==1?3:332748118,(mod-1)/n);
		for(int i=2;i<n/2;i++)w[i]=1ll*w[i-1]*w[1]%mod;
		return w;
	}
	struct Poly{
		vi a;
		Poly(){vi().swap(a);}
		Poly(int x){vi().swap(a);a.resize(x);}
		int size(){return a.size();}
		void resize(int x){a.resize(x);}
		int &operator[](int i){return a[i];}
	};
	void DFT(Poly &a){//转置 
		int n=a.size();
		for(int i=n/2;i;i>>=1){
			int *w=getw(i<<1,1);
			for(int j=0;j<n;j+=i<<1){
				for(int k=0;k<i;++k){
					int u=a[j+k],v=a[j+i+k];
					a[j+k]=add(u,v);
					a[j+i+k]=del(1ll*u*w[k]%mod,1ll*v*w[k]%mod);
				}
			}
		}
	}
	void IDFT(Poly &a){
		int n=a.size();
		for(int i=1;i<n;i<<=1){
			int *w=getw(i<<1,-1);
			for(int j=0;j<n;j+=i<<1){
				for(int k=0;k<i;++k){
					int v=1ll*a[j+i+k]*w[k]%mod;
					a[j+i+k]=del(a[j+k],v);
					cadd(a[j+k],v);
				}
			}
		}
		int inv=qpow(n,mod-2);
		for(int i=0;i<n;i++)a[i]=1ll*a[i]*inv%mod;
	}
	Poly operator*(Poly f,Poly g){
		int n=f.size(),m=g.size();
		int len=1,ct=0;
		while(len<=n+m)len<<=1,++ct;
		f.resize(len);g.resize(len);
		DFT(f);
		DFT(g);
		for(int i=0;i<len;i++)f[i]=1ll*f[i]*g[i]%mod;
		IDFT(f);
		f.resize(n+m-1);
		return f;
	}
}
using namespace MyPoly;
int n,A[4],B[4],C[4];
int fac[N],inv[N];
void solve(){
	read(n);
	for(int i=1;i<=3;i++)read(A[i]);
	for(int i=1;i<=3;i++)read(B[i]);
	for(int i=1;i<=3;i++)read(C[i]);
	int a[6][7]={
		{1,0,1,0,1,0,A[2]-A[1]},
		{0,1,0,1,0,1,A[3]-A[1]},
		{1,0,0,-1,-1,1,B[2]-B[1]},
		{0,1,1,-1,-1,0,B[3]-B[1]},
		{1,0,-1,1,0,-1,C[2]-C[1]},
		{0,1,-1,0,1,-1,C[3]-C[1]}
	};
	for(int i=0;i<6;i++){
		int p=-1;
		for(int j=i;j<6;j++)
			if(a[j][i]){
				p=j;
				break;
			}
		if(p==-1){puts("0");return ;}
		swap(a[i],a[p]);
		for(int j=i+1;j<7;j++)
			if(a[i][j]%a[i][i]){
				puts("0");
				return ;
			}
			else a[i][j]/=a[i][i];
		a[i][i]=1;
		for(int j=0;j<6;j++)if(i!=j){
			int t=a[j][i];
			for(int k=0;k<7;k++)
				a[j][k]-=a[i][k]*t;
		}
	}
	int coef=fac[n];
	for(int i=0;i<6;i++){
		n-=a[i][6];
	}
	if(n<0 || n%3){
		puts("0");
		return ;
	}
	n/=3;
	int lim[3];
	lim[0]=max({0,-a[0][6],-a[1][6]});
	lim[1]=max({0,-a[2][6],-a[3][6]});
	lim[2]=max({0,-a[4][6],-a[5][6]});
	Poly f(n+1),g(n+1),h(n+1);
	for(int i=lim[0];i<=n;i++)f[i]=1ll*inv[i]*inv[i+a[0][6]]%mod*inv[i+a[1][6]]%mod;
	for(int i=lim[1];i<=n;i++)g[i]=1ll*inv[i]*inv[i+a[2][6]]%mod*inv[i+a[3][6]]%mod;
	for(int i=lim[2];i<=n;i++)h[i]=1ll*inv[i]*inv[i+a[4][6]]%mod*inv[i+a[5][6]]%mod;
	f=f*g*h;
	int ans=1ll*f[n]*coef%mod;
	cout<<ans<<'\n';
}
signed main(){
	int tid;read(tid);
	n=500000;
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=qpow(fac[n],mod-2);for(int i=n-1;~i;--i)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	int T=1;
	read(T);
	while(T--)solve();
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
2 0 0
1 1 0
1 0 1

output:


result: