QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84808 | #990. Colorful Components | Kostlin | WA | 6ms | 4584kb | C++14 | 2.0kb | 2023-03-06 19:16:19 | 2023-03-06 19:16:56 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define fi first
#define sc second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int N=305,mod=998244353,inv2=(mod+1)/2;
inline int read() {
int x=0,flag=0;char ch=getchar();
while(ch<'0'||ch>'9') {flag|=(ch=='-');ch=getchar();}
while('0'<=ch&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return flag?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}
inline void swp(int&x,int&y) {x^=y^=x^=y;}
inline int as(int x) {return x>0?x:-x;}
int n,K,c[N],tr[N],ifac[N],C[N][N],f[N][N],pw[N][N];
int F[N],G[N];
inline int ksm(int a,int b=mod-2) {
int ans=1;
while(b) {
if(b&1) ans=1ll*ans*a%mod;
a=1ll*a*a%mod;
b>>=1;
} return ans;
}
inline void prep() {
tr[1]=1;
for(int i=2;i<=n;++i) tr[i]=ksm(i,i-2);
ifac[0]=1;
for(int i=1;i<=n;++i) ifac[i]=1ll*ifac[i-1]*ksm(i)%mod;
C[0][0]=1;
for(int i=1;i<=n;++i) {
C[i][0]=C[i][i]=1;
for(int j=1;j<i;++j)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
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;
}
f[0][0]=1;
for(int p=1;p<=n;++p)
for(int i=1;i<=n;++i)
for(int j=1;j<=mn(i,K);++j)
f[p][i]=(f[p][i]+1ll*f[p-1][i-j]*C[i][j]%mod*tr[j]%mod*j)%mod;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
f[i][j]=1ll*f[i][j]*ifac[i]%mod;
}
int main() {
n=read();K=read();
for(int i=1,x;i<=n;++i) {
x=read();
++c[x];
}
prep();
F[0]=1;
int tot=0;
for(int i=1;i<=n;++i) {
if(!c[i]) continue;
++tot;
for(int j=0;j<=n;++j)
for(int k=1;k<=c[i];++k)
G[j+k]=(G[j+k]+1ll*F[j]*f[k][c[i]]%mod*pw[n-c[i]][k-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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 4584kb
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'