QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506824 | #8047. DFS Order 4 | qwqUwU_ | AC ✓ | 1478ms | 6216kb | C++17 | 1.7kb | 2024-08-05 22:51:06 | 2024-08-05 22:51:07 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int mod=998244353;
inline int fp(int x,ll p=mod-2,int m=mod,int res=1){
for(;p;p>>=1){if(p&1)res=1ll*res*x%m;x=1ll*x*x%m;}
return res;
}
inline void Ad(int &x,int y){x=x+y>=mod?x+y-mod:x+y;}
inline void Mi(int &x,int y){x=x-y<0?x-y+mod:x-y;}
const int N=802;
int n;
int f[N][N],g[N],fac[N],iv[N];
int main() {
//freopen("data.in", "r", stdin);
// freopen("myans.out","w",stdout);
n=read(),mod=read();
fac[0]=1;rep(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
iv[1]=1;rep(i,2,n)iv[i]=1ll*iv[mod%i]*(mod-mod/i)%mod;
g[1]=1;
rep(i,1,n-1){
Ad(f[i][0],g[i]);
Ad(g[i+1],1ll*f[i][0]*iv[i+1]%mod);
rep(j,0,i-1)rep(k,2,min(i,n-i))Ad(f[i+k][j],1ll*f[i][j]*g[k]%mod*k%mod*iv[i+k]%mod);
rep(j,0,i-1)rep(k,1,min(i,n-i))Mi(f[i+k][j+1],1ll*f[i][j]*g[k]%mod*k%mod*iv[i+k]%mod);
if(i>1)rep(k,1,min(i-1,n-i))rep(j,0,k-1)Ad(f[i+k][j],1ll*g[i]*f[k][j]%mod*i%mod*iv[i+k]%mod);
rep(k,1,min(i-1,n-i))rep(j,0,k-1)Mi(f[i+k][j+1],1ll*g[i]*f[k][j]%mod*i%mod*iv[i+k]%mod);
rep(j,1,i-1)Ad(f[i+1][j-1],1ll*f[i][j]*iv[i+1]%mod);
}
cout<<1ll*g[n]*fac[n]%mod<<"\n";
//rep(i,1,n)printf("%lld\n",1ll*g[i]*fac[i]%mod);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 4ms
memory: 4008kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 1238ms
memory: 6040kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 1433ms
memory: 6208kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 1252ms
memory: 5956kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 1326ms
memory: 6044kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 1211ms
memory: 5996kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 1344ms
memory: 6140kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 1478ms
memory: 6148kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 1448ms
memory: 6136kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 1332ms
memory: 6008kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 1470ms
memory: 6216kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed