QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#339044#8047. DFS Order 4xlwangWA 984ms6264kbC++142.1kb2024-02-26 17:08:252024-02-26 17:08:26

Judging History

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

  • [2024-02-26 17:08:26]
  • 评测
  • 测评结果:WA
  • 用时:984ms
  • 内存:6264kb
  • [2024-02-26 17:08:25]
  • 提交

answer

#include<bits/stdc++.h>
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define randfind(l,r) (rnd()%((r)-(l)+1)+(l))
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
//inline void init(){
//	int t=read();
//	while(t--) work();
//}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int Maxn=8e2+10;
int mod;
inline int ksm(int x,int y){
    int sum=1;
    while(y){
        if(y&1) sum=1ll*sum*x%mod;
        y=y/2;x=1ll*x*x%mod;
    }
    return sum;
}
int n;
inline void init(){
    n=read();mod=read();
}
int inv[Maxn];
inline int getfac(int x){
    int sum=1;
    fr(i,1,x) sum=1ll*sum*i%mod;
    return sum;
}
int f[Maxn][Maxn];
inline void add(int &x,int y){
    x+=y;if(x>=mod) x-=mod;
}
inline void work(){
    inv[0]=1;
    fr(i,1,n) inv[i]=ksm(i,mod-2);
    // cout<<ksm(2,mod-2)<<endl;
    f[1][0]=1;
    fr(i,2,n) fr(j,0,i){
        f[i][j]=1ll*f[i-1][j+1]*inv[i]%mod;
        if(j==0) add(f[i][j],1ll*f[i-1][j]*inv[i]%mod);
        fr(k,1,i-j){
            add(f[i][j],1ll*f[i-k][j]*f[k-1][0]%mod*inv[i]%mod);
            if(j) add(f[i][j],mod-1ll*f[i-k][j-1]*(f[k-1][0]+(k==1))%mod*inv[i]%mod);
        }
    }
    int ans=0;
    // fr(i,1,n) fr(j,0,n) cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
    // cout<<getfac(n)<<endl;
    writeln(1ll*f[n-1][0]*getfac(n-1)%mod);
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();work();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 826ms
memory: 6004kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 958ms
memory: 6244kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 840ms
memory: 6156kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 887ms
memory: 6116kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 811ms
memory: 6192kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 905ms
memory: 5996kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 972ms
memory: 6264kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 969ms
memory: 6252kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 890ms
memory: 6000kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 984ms
memory: 6144kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: -100
Wrong Answer
time: 0ms
memory: 3752kb

input:

1 1001338769

output:

0

result:

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