QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446106#8047. DFS Order 4liuhengxiWA 55ms3900kbC++141.5kb2024-06-16 21:30:452024-06-16 21:30:46

Judging History

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

  • [2024-06-16 21:30:46]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:3900kb
  • [2024-06-16 21:30:45]
  • 提交

answer

// created:  Jun/16/2024 20:39:51
#include<cstdio>
#include<cctype>
#include<algorithm>
#define F(i,l,r) for(int i=(l),i##_end=(r);i<i##_end;++i)
#define I128 //||is_same<T,__int128_t>::value||is_same<T,__uint128_t>::value
using namespace std;
template<typename T>enable_if_t<is_integral<T>::value I128,void> readmain(T &x)
{
	bool neg=false;int c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=true;
	for(x=0;isdigit(c);c=getchar())x=(T)(10*x+(c-'0'));
	if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
typedef unsigned long long ull;
typedef __uint128_t u128;
struct barrett
{
	ull mod,inv;
	void init(int mod_){inv=(-1ull)/(mod=mod_);}
	int operator()(ull x)
	{
		x-=(ull)((u128)x*inv>>64)*mod;
		if(x>>63)x+=mod;
		return (int)x;
	}
};
constexpr int N=805;
int mod;barrett bar;
void reduce(int &x){(x>=mod)&&(x-=mod);}
void reduce_(int &x){(x<0)&&(x+=mod);}
int n,inv[N],f[N],g[N][N];
int main()
{
	read(n,mod);bar.init(mod);
	inv[1]=1;
	F(i,2,n+1)inv[i]=bar((ull)(mod-mod/i)*inv[mod%i]);
	F(i,1,n+1)
	{
		f[i]=g[i-1][0]+(i==1);
		g[i][0]=f[i];
		F(j,1,i-1)
		{
			g[i][0]=bar(g[i][0]+(ull)f[i-j]*g[j][0]);
			F(k,1,min(j,n-i)+1)g[i][k]=bar(g[i][k]+(ull)f[i-j]*(g[j][k]-g[j][k-1]+mod));
		}
		F(j,0,i-1)reduce_(g[i][j+1]-=g[i-1][j]);
		F(j,1,i-1)reduce(g[i][j-1]+=g[i-1][j]);
		F(j,0,i)g[i][j]=bar((ull)inv[i]*g[i][j]);
	}
	int ans=f[n];
	F(i,1,n)ans=bar((ull)i*ans);
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 1548kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 0ms
memory: 1812kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: -100
Wrong Answer
time: 55ms
memory: 3900kb

input:

756 1001338769

output:

897564641

result:

wrong answer 1st numbers differ - expected: '901942543', found: '897564641'