QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422935#990. Colorful ComponentswdnmdwrnmmpWA 14ms5812kbC++142.2kb2024-05-27 20:21:042024-05-27 20:21:05

Judging History

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

  • [2024-05-27 20:21:05]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:5812kb
  • [2024-05-27 20:21:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

const int N=305, mod=1e9+7;
int qpow(int x,int y){
    int res=1;
    while(y){
        if(y%2) res=res*x%mod;
        x=x*x%mod;
        y/=2;
    }
    return res;
}int inv(int x){return qpow(x,mod-2);};
int fac[N], ifac[N];
void init(){
    fac[0]=1;
    rep(i,1,N-1){
        fac[i]=fac[i-1]*i%mod;
    }
    ifac[N-1]=inv(fac[N-1]);
    per(i,N-1,1){
        ifac[i-1]=ifac[i]*i%mod;
    }
}
int C(int m,int n){
    return fac[m]*ifac[n]%mod*ifac[m-n]%mod;
}

int n,K;
int F[N][N];
int calc(int n,int m){
    if(m==1){
        return 1;
    }
    return F[n][m-2];
}
map<int,int> cnt;
int f[N][N], w[N], g[N][N];

signed main(){
    #ifndef ONLINE_JUDGE
    assert(freopen(".in","r",stdin));
    // assert(freopen(".out","w",stdout));
    #endif
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    init();
    cin>>n>>K;
    rep(i,0,n){
        rep(j,0,n){
            F[i][j]=qpow(i,j);
        }
    }
    rep(i,1,n){
        int c; cin>>c;
        cnt[c]++;
    }
    f[0][0]=1;
    rep(i,0,n){
        rep(j,0,i){
            rep(k,1,min(n-i,K)){
                (f[i+k][j+1]+= C(i+k-1,k-1)*k%mod*f[i][j]%mod*calc(k,k) )%=mod;
            }
            if(j==1){
                if(i<=K){
                    (w[i]+= ((i-j)%2? mod-1: 1)*(i<=1? 1: F[i][i-2]) )%=mod;
                }
            }
            else if(j>1){
                (w[i]+= f[i][j]*((i-j)%2? mod-1: 1)%mod*calc(i,j) )%=mod;
            }
        }
    }
    g[0][0]=1;
    int tot=0;
    for(auto x:cnt){
        int R=tot+x.se;
        rep(i,tot,R-1){
            rep(j,0,i){
                rep(k,1,R-i){
                    (g[i+k][j+1]+= C(i+k-1,k-1)*k%mod*w[k]%mod*g[i][j] )%=mod;
                }
            }
        }
        tot=R;
    }
    int ans=0;
    rep(j,1,n){
        (ans+= g[n][j]*calc(n,j) )%=mod;
    }
    cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 3
1
1
3
1
5

output:

125

result:

ok "125"

Test #2:

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

input:

4 2
2
1
1
1

output:

7

result:

ok "7"

Test #3:

score: -100
Wrong Answer
time: 14ms
memory: 5812kb

input:

300 16
2
2
2
4
5
1
5
3
5
4
2
1
4
4
4
5
2
1
5
4
3
4
5
3
5
5
1
3
1
1
2
5
5
3
3
2
5
2
3
2
2
4
2
2
2
4
4
2
2
4
1
3
3
4
1
3
3
4
3
4
3
5
5
4
3
3
1
2
1
2
5
2
2
4
3
3
5
3
2
4
3
5
1
4
5
5
2
3
2
3
4
4
5
5
5
5
4
5
3
2
4
4
4
3
5
3
1
1
3
5
5
4
5
2
5
5
5
2
2
2
3
1
5
4
1
4
3
5
1
4
4
2
5
2
2
4
5
3
4
3
3
4
2
5
1
1
3...

output:

673912381

result:

wrong answer 1st words differ - expected: '540253743', found: '673912381'