QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85183 | #990. Colorful Components | wind_cross | WA | 9ms | 4352kb | C++14 | 2.0kb | 2023-03-07 07:41:14 | 2023-03-07 07:41:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline char nc()
{
static char buf[1000000],*l,*r;
return l==r&&(r=(l=buf)+fread(buf,1,1000000,stdin),l==r)?EOF:*l++;
}
template <class code>inline code read(const code &a)
{
code x=0;short w=0;char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=nc();}
while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=nc();}
return w?-x:x;
}
void print(long long x){
if(x<0)putchar('-'),x=-x;
if(x>=10)print(x/10);
putchar(x%10+48);
}
const int mod=998244353;
int dp[305][305][305],qz[305][305][305],jc[305],inv[305],fa[305],kx[305][305],t[305];
int dp1[305][305],pw[305][305],F[305],G[305];
int ksm(int x,int y){
int now=1;
while(y){
if(y&1)now=1ll*now*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return now;
}
int main(){
// freopen("text.in","r",stdin);
// freopen("text.out","w",stdout);
int n=read(n),k=read(k);
for(int i=1;i<=n;i++){
pw[i][0]=1;
for(int j=1;j<=n;j++){
pw[i][j]=1ll*pw[i][j-1]*i%mod;
}
}
fa[1]=1;
for(int i=2;i<=n;i++)fa[i]=ksm(i,i-2);
jc[0]=1;
for(int i=1;i<=n;i++)jc[i]=1ll*jc[i-1]*i%mod;
inv[n]=ksm(jc[n],mod-2);
for(int i=n-1;i>=0;i--)inv[i]=1ll*inv[i+1]*(i+1)%mod;
kx[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int p=1;p<=j&&p<=k;p++){
kx[i][j]=(kx[i][j]+1ll*kx[i-1][j-p]*fa[p]%mod*jc[j]%mod*p%mod*inv[p]%mod*inv[j-p])%mod;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)kx[i][j]=1ll*kx[i][j]*inv[i]%mod;
}
for(int i=1;i<=n;i++){
int x=read(x);
t[x]++;
}
F[0]=1;
int tot=0;
for(int i=1;i<=n;++i) {
if(!t[i])continue;
int z=t[i];
++tot;
for(int j=0;j<=n;++j)
for(int p=1;p<=z;++p)
G[j+p]=(G[j+p]+1ll*F[j]*kx[p][z]%mod*pw[n-z][p-1])%mod;
for(int j=0;j<=n;++j)F[j]=G[j],G[j]=0;
}
if(tot==1){
if(k==n)printf("%d\n",ksm(n,n-2));
else printf("0\n");
return 0;
}
int ans=0;
for(int i=tot;i<=n;++i)ans=(ans+1ll*F[i]*ksm(n,tot-2))%mod;
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 9ms
memory: 4352kb
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:
840745403
result:
wrong answer 1st words differ - expected: '540253743', found: '840745403'