QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#507157#1084. Beautiful Sequence UnravelingxlwangAC ✓377ms6320kbC++142.9kb2024-08-06 11:48:262024-08-06 11:48:26

Judging History

This is the latest submission verdict.

  • [2024-08-06 11:48:26]
  • Judged
  • Verdict: AC
  • Time: 377ms
  • Memory: 6320kb
  • [2024-08-06 11:48:26]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#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 pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
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(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
//	int t=read();
//	while(t--) work();
//}
const int Maxn=4e2+10;
int n,m,mod;
inline int ksm(int x,int y=mod-2){
    int sum=1;
    while(y){
        if(y&1) sum=1ll*sum*x%mod;
        y=y/2;x=1ll*x*x%mod;
    }return sum;
}
int inum[Maxn];
int pw[Maxn][Maxn],ipw[Maxn][Maxn],C[Maxn][Maxn];
inline void into(){
    inum[0]=1;fr(i,1,n) inum[i]=ksm(i);
    // fr(i,1,n) cout<<i<<' '<<inum[i]<<endl;
    fr(i,1,n){
        pw[i][0]=1;
        ipw[i][0]=1;
        fr(j,1,n){
            pw[i][j]=1ll*pw[i][j-1]*i%mod;
            ipw[i][j]=1ll*ipw[i][j-1]*inum[i]%mod;
        }
    }
    C[0][0]=1;
    fr(i,1,n){
        C[i][0]=1;
        fr(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
}
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void init(){
    n=read();m=read();mod=read();into();
}
int f[Maxn][Maxn],s[Maxn][2];
int g[Maxn];
inline void work(){
    fr(j,1,n){
        fr(i,1,n) s[i][0]=s[i][1]=0;
        fr(i,1,n){
            f[i][j]=pw[j][i];
            fr(t,1,j){
                // cout<<"*"<<i<<' '<<j<<' '<<s[t][0]<<' '<<s[t][1]<<endl;
                add(f[i][j],mod-1ll*pw[t][i]*s[t][0]%mod);
                add(f[i][j],1ll*pw[t-1][i]*s[t][1]%mod);
            }
            // cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
            fr(t,1,j){
                add(s[t][0],1ll*ipw[t][i]*(f[i][j-t+1]-f[i][j-t]+mod)%mod);
                add(s[t][1],1ll*ipw[t-1][i]*(f[i][j-t+1]-f[i][j-t]+mod)%mod);
            }
        }
    }
    int ans=0,s=1;
    // fr(i,1,n) fr(j,1,n) cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
    fr(i,1,n){
        g[i]=f[n][i];
        fr(j,1,i-1) add(g[i],mod-1ll*g[j]*C[i][j]%mod);
        s=1ll*s*(m-i+1)%mod;s=1ll*s*inum[i]%mod;
        // cout<<i<<' '<<g[i]<<endl;
        add(ans,1ll*s*g[i]%mod);
    }writeln(ans);
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();work();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5812kb

input:

2 2 1000000007

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

3 4 1000000009

output:

36

result:

ok 1 number(s): "36"

Test #3:

score: 0
Accepted
time: 71ms
memory: 5152kb

input:

228 112263 998244353

output:

379700769

result:

ok 1 number(s): "379700769"

Test #4:

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

input:

1 1 998595277

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

2 2 998683811

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3 1 998277223

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

4 1 998365733

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 371ms
memory: 6304kb

input:

400 100000000 998244353

output:

318973800

result:

ok 1 number(s): "318973800"

Test #9:

score: 0
Accepted
time: 376ms
memory: 6124kb

input:

400 1 1000000007

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

2 9 999603883

output:

72

result:

ok 1 number(s): "72"

Test #11:

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

input:

1 1 998784541

output:

1

result:

ok 1 number(s): "1"

Test #12:

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

input:

3 3 999209353

output:

12

result:

ok 1 number(s): "12"

Test #13:

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

input:

4 12 999787531

output:

16544

result:

ok 1 number(s): "16544"

Test #14:

score: 0
Accepted
time: 375ms
memory: 6128kb

input:

400 3 998785127

output:

505031599

result:

ok 1 number(s): "505031599"

Test #15:

score: 0
Accepted
time: 376ms
memory: 6088kb

input:

400 77 999400643

output:

877578741

result:

ok 1 number(s): "877578741"

Test #16:

score: 0
Accepted
time: 376ms
memory: 6304kb

input:

400 374 998458939

output:

202865317

result:

ok 1 number(s): "202865317"

Test #17:

score: 0
Accepted
time: 377ms
memory: 6068kb

input:

400 77435643 999245677

output:

833344996

result:

ok 1 number(s): "833344996"

Test #18:

score: 0
Accepted
time: 373ms
memory: 6288kb

input:

399 72119824 999010279

output:

188282648

result:

ok 1 number(s): "188282648"

Test #19:

score: 0
Accepted
time: 366ms
memory: 6248kb

input:

398 22521432 999827603

output:

986913334

result:

ok 1 number(s): "986913334"

Test #20:

score: 0
Accepted
time: 364ms
memory: 6320kb

input:

397 77955743 998803427

output:

32764673

result:

ok 1 number(s): "32764673"