QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339047 | #8047. DFS Order 4 | xlwang | AC ✓ | 983ms | 6320kb | C++14 | 2.1kb | 2024-02-26 17:09:10 | 2024-02-26 17:09:13 |
Judging History
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(){
if(n==1){
writeln(1);
return;
}
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;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 3ms
memory: 4128kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 831ms
memory: 6140kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 958ms
memory: 6252kb
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: 888ms
memory: 6052kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 814ms
memory: 6044kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 901ms
memory: 6188kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 976ms
memory: 6264kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 965ms
memory: 6320kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 894ms
memory: 6052kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 983ms
memory: 6304kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed