QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446107#8047. DFS Order 4liuhengxiAC ✓63ms4052kbC++141.5kb2024-06-16 21:31:332024-06-16 21:31:34

Judging History

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

  • [2024-06-16 21:31:34]
  • 评测
  • 测评结果:AC
  • 用时:63ms
  • 内存:4052kb
  • [2024-06-16 21:31:33]
  • 提交

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_)+1;}
	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;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 54ms
memory: 3872kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 61ms
memory: 3996kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 50ms
memory: 3900kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 56ms
memory: 4052kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 52ms
memory: 4032kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 58ms
memory: 3932kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 62ms
memory: 4028kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 62ms
memory: 4012kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

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

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 63ms
memory: 3996kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed