QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767729#8047. DFS Order 4zhulexuanAC ✓468ms8480kbC++141.9kb2024-11-20 21:55:362024-11-20 21:55:37

Judging History

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

  • [2024-11-20 21:55:37]
  • 评测
  • 测评结果:AC
  • 用时:468ms
  • 内存:8480kb
  • [2024-11-20 21:55:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
    T w=1; n=0; char ch=getchar();
    while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
    while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
    n*=w;
}
template<typename T>inline void write(T x){
    if (x==0){ putchar('0'); return ; }
    T tmp;
    if (x>0) tmp=x;
    else tmp=-x;
    if (x<0) putchar('-');
    char F[105];
    long long cnt=0;
    while (tmp){
        F[++cnt]=tmp%10+48;
        tmp/=10;
    }
    while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 805; ll mod;
ll pw(ll x,ll y){
    ll ans = 1;
    while (y){
        if (y&1) ans = ans*x %mod;
        x = x*x %mod;
        y >>= 1;
    }
    return ans;
}
ll n;
ll inv[N];
ll f[N][N];
int main(){
	// freopen("a.in","r",stdin);
//	freopen(".out","w",stdout);
    ll i,j,k;
    read(n); read(mod);
    f[0][0] = 1;
    inv[0] = 1;
    fr(i,1,n) inv[i] = pw(i,mod-2);
    fr(i,1,n){
        fr(j,0,n-i){
            f[i][j] = f[i-1][0];//1.
            fr(k,2,i-2){
                // ( f[i][j] += f[k][0] * f[i-k][j] ) %=mod;
                // ( f[i][j] += f[k][j] * (f[i-k][0]-f[i-k][j+k]) ) %=mod;
                ( f[i][j] += f[i-k][j] * (f[k][0]-f[k][j+i-k-1]) ) %=mod;//2.
            }
            f[i][j] = f[i][j]*inv[i+j-1] %mod;//3.
            // printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
        }
    }
    ll ans = f[n][0];
    fr(i,1,n-1) ans = ans*i %mod;
    ans = (ans%mod+mod)%mod; write(ans);
    return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000 -std=c++11 -O2

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 394ms
memory: 8104kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 458ms
memory: 8328kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 401ms
memory: 8316kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 425ms
memory: 8256kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 386ms
memory: 8000kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 433ms
memory: 8296kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 464ms
memory: 8388kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 464ms
memory: 8480kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 425ms
memory: 8264kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 468ms
memory: 8408kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed