QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423052 | #990. Colorful Components | OIer2008 | WA | 9ms | 6236kb | C++14 | 1.8kb | 2024-05-27 20:54:57 | 2024-05-27 20:54:59 |
Judging History
answer
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fd(i,r,l) for(int i=r;i>=l;--i)
#define ll long long
#define I inline int
#define V inline void
#define B inline bool
#define L inline ll
#define pi pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vii vector<pi>
using namespace std;
const int N=305,mod=998244353;
char St;
I read() {
int x=0,y=1;char c=getchar();
while(c<48||c>57) {if(c==45)y=-y;c=getchar();}
while(c>=48&&c<=57) x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*y;
}
int n,k,s[N];
ll pw[N],f[N][N],g[N][N],ans(1),C[N][N],inv[N];
L ksm(ll x,int y=mod-2) {
ll t=1;for(;y;y>>=1,x=x*x%mod)if(y&1)t=t*x%mod;return t;
}
V add(ll &x,ll y) {
x+=y;if(x>=mod) x-=mod;
}
char Ed;
int main() {
cerr<<"memory:"<<(&St-&Ed)/1024.0<<endl;
n=read();k=read();
fo(i,1,n) s[read()]++;
C[0][0]=1;
fo(i,1,n) {
inv[i]=ksm(i);
C[i][0]=1;
fo(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
fo(i,1,n) {
pw[i]=1;
fo(j,1,i-2) pw[i]=pw[i]*i%mod;
}
f[0][0]=mod-1;
fo(i,1,n) fo(j,1,min(i,k)) fo(l,1,i) add(f[i][l],mod-1ll*C[i][j]*f[i-j][l-1]%mod*pw[j]%mod*inv[l]%mod*j%mod);
fo(i,1,n) {
fo(j,1,i) add(f[i][0],f[i][j]*ksm(i,j-2+mod-1)%mod);
}
// fo(i,1,n) printf("! %d\n",f[i][0]);
fo(i,1,n) {
if(!s[i]) continue;
memset(g,0,sizeof(g));
g[0][0]=1;
fo(j,1,s[i]) fo(k,1,j) fo(l,1,j) add(g[j][l],g[j-k][l-1]*k%mod*C[j][k]%mod*f[k][0]%mod*n%mod*inv[l]%mod);
ll sum=0;
fo(j,1,s[i]) {
// fo(l,1,j) printf("%d ",g[j][l]);
// puts("");
add(sum,g[s[i]][j]);
}
// printf("%d %lld\n",s[i],sum);
ans=ans*sum%mod;
}
printf("%lld\n",ans*ksm(n*n,mod-2)%mod);
cerr<<"time:"<<clock()<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4784kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6024kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 9ms
memory: 6236kb
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'