QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#422954 | #990. Colorful Components | wdnmdwrnmmp | WA | 18ms | 5720kb | C++14 | 2.3kb | 2024-05-27 20:26:39 | 2024-05-27 20:26:39 |
Judging History
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<=1? 1: F[i][i-2]) )%=mod;
}
}
else if(j>1){
(w[i]+= f[i][j]*(j%2? 1: mod-1)%mod*calc(i,j) )%=mod;
}
}
}
// cout<<f[1][1]<<' '<<f[2][1]<<' '<<f[2][2]<<endl;
// cout<<w[1]<<' '<<w[2]<<endl;
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=g[n][1]*inv(n)%mod;
rep(j,2,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: 3712kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 18ms
memory: 5720kb
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:
821828316
result:
wrong answer 1st words differ - expected: '540253743', found: '821828316'