QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764932#8047. DFS Order 4L_WaveAC ✓515ms41360kbC++201.5kb2024-11-20 11:15:122024-11-20 11:15:12

Judging History

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

  • [2024-11-20 11:15:12]
  • 评测
  • 测评结果:AC
  • 用时:515ms
  • 内存:41360kb
  • [2024-11-20 11:15:12]
  • 提交

answer

// Problem: # 8047. DFS Order 4
// Author: XZC(L_Wave)
// Language: Cpp/G++20
// Contest: 
// URL: https://qoj.ac/problem/8047
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Create Time: not 2024-11-20 11:04:29, but 1926-08-17 11:45:14
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i <= i##ABRACADABRA; i++)
#define drep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i >= i##ABRACADABRA; i--)
using namespace std;
using ll = long long;

ll mod;
int n;
 
ll fac[2000010], ifac[2000010];
ll qpow(ll x, ll y) {
  if (y < 0)
    y += mod - 1 + mod - 1;
  if (x == mod - 1)
    return y & 1 ? mod - 1 : 1;
  ll res = 1;
  for (; y; y >>= 1) {
    if (y & 1) {
      res *= x;
      res %= mod;
    }
    x *= x;
    x %= mod;
  }
  return res;
}
void init() {
  fac[0] = 1;
  rep(i, 1, 2000005)
    fac[i] = fac[i-1] * i % mod;
  ifac[2000005] = qpow(fac[2000005], -1);
  drep(i, 2000005, 1)
    ifac[i-1] = ifac[i] * i % mod;
}
ll choose(int x, int y) {
  if (x < y || y < 0)
    return 0;
  return fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

ll dp[888][888];

int main() {
  scanf("%d%lld",&n,&mod);
  init();
  dp[1][0]=1;
  rep(i,2,n)rep(j,0,n-i){
    dp[i][j]=dp[i-1][0];
    rep(k,2,i-2)(dp[i][j]+=dp[i-k][j]*(dp[k][0]-dp[k][i-1-k+j]+mod)%mod)%=mod;
    (dp[i][j]*=ifac[i+j-1]*fac[i+j-2]%mod)%=mod;
  }
  printf("%lld\n",dp[n][0]*fac[n-1]%mod);
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 36928kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 16ms
memory: 36588kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 25ms
memory: 39064kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 442ms
memory: 41308kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 495ms
memory: 41316kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 451ms
memory: 41308kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 463ms
memory: 41312kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 417ms
memory: 41312kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 475ms
memory: 41312kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 515ms
memory: 41304kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 512ms
memory: 41360kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 471ms
memory: 41308kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 514ms
memory: 41312kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: 0
Accepted
time: 32ms
memory: 36216kb

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 16ms
memory: 37092kb

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 28ms
memory: 36304kb

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

score: 0
Accepted
time: 28ms
memory: 35248kb

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed