QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526372#8047. DFS Order 4CryingAC ✓1623ms6208kbC++141.2kb2024-08-21 14:31:002024-08-21 14:31:01

Judging History

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

  • [2024-08-21 14:31:01]
  • 评测
  • 测评结果:AC
  • 用时:1623ms
  • 内存:6208kb
  • [2024-08-21 14:31:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 810; int mod;
int addv(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
int subv(int x,int y){return (x>=y)?(x-y):(x-y+mod);}
void add(int& x,int y){x = addv(x,y);}
void sub(int& x,int y){x = subv(x,y);}
int qpow(int a,int n){
    int res = 1; a%=mod;
    while(n){
        if(n&1)res = 1ll*res*a%mod;
        n>>=1; a = 1ll*a*a%mod;
    }
    return res;
}
int qinv(int a){return qpow(a,mod-2);}
//
int n,inv[MAXN],g[MAXN][MAXN]; //单点/序列

int main(){
    cin>>n>>mod;
    for(int i=1;i<=n;i++)inv[i] = qinv(i);

    for(int i=0;i<=n+1;i++)g[0][i] = g[1][i] = 1;
    for(int i=2;i<n;i++){
        for(int j=0;j<=n;j++){
            g[i][j] = g[i-1][j+1];
            for(int k=1;k<i-1;k++){ 
                add(g[i][j],1ll*g[k][j]*g[i-1-k][0]%mod);
            }
            if(j){
                for(int k=1;k<=i-1;k++){
                    sub(g[i][j],1ll*g[k][j-1]*g[i-1-k][0]%mod);
                }
            }
            g[i][j] = 1ll*g[i][j]*qinv(i)%mod;
        }
    }
    //
    int ans = g[n-1][0];
    for(int i=1;i<n;i++)ans = 1ll*ans*i%mod;
    cout<<ans<<endl;
    return 0;
}

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

詳細信息

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 3ms
memory: 3948kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

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

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 1573ms
memory: 6048kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 1384ms
memory: 5956kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 1460ms
memory: 6056kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 1340ms
memory: 5980kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

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

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 1603ms
memory: 6028kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 1590ms
memory: 6208kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 1470ms
memory: 5956kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 1623ms
memory: 6160kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

score: 0
Accepted
time: 1ms
memory: 3728kb

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed