Submission #34636438
Source Code Expand
#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n")
#include"/home/xay5421/debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
using namespace std;
using LL=long long;
using ULL=unsigned long long;
const int P=998244353;
int ad(int k1,int k2){return k1+k2>=P?k1+k2-P:k1+k2;}
int su(int k1,int k2){return k1-k2<0?k1-k2+P:k1-k2;}
int mu(int k1,int k2){return 1ULL*k1*k2%P;}
void uad(int&k1,int k2){(k1+=k2)>=P&&(k1-=P);}
void usu(int&k1,int k2){(k1-=k2)<0&&(k1+=P);}
template<class... T>int ad(int k1,T... k2){return ad(k1,ad(k2...));}
template<class... T>int su(int k1,T... k2){return su(k1,ad(k2...));}
template<class... T>int mu(int k1,T... k2){return mu(k1,mu(k2...));}
template<class... T>void uad(int&k1,T... k2){return uad(k1,ad(k2...));}
template<class... T>void usu(int&k1,T... k2){return usu(k1,ad(k2...));}
int po(int k1,int k2){
int k3=1;
for(;k2;k2>>=1,k1=mu(k1,k1))if(k2&1)k3=mu(k3,k1);
return k3;
}
const int N=5005;
int n,K,a[N],fac[N],ifac[N];
int C(int n,int m){
if(m<0||n<m)return 0;
return mu(fac[n],ifac[m],ifac[n-m]);
}
int dp[N],new_dp[N];
void push(int x){
memset(new_dp,0,sizeof(new_dp));
rep(i,0,n)if(dp[i]){
for(int j=0;j<=x&&j<=i;++j){
uad(new_dp[i+x-j],mu(fac[x],dp[i],C(i,j),C(i+x-j,x-j)));
}
}
memcpy(dp,new_dp,sizeof(dp));
}
int main(){
fac[0]=1;
rep(i,1,N-1)fac[i]=mu(fac[i-1],i);
ifac[N-1]=po(fac[N-1],P-2);
per(i,N-1,1)ifac[i-1]=mu(ifac[i],i);
rd(n),rd(K);
rep(i,1,n)rd(a[i]);
sort(a+1,a+n+1);
dp[0]=1;
for(int i=1,j;i<=n;i=j){
j=i+1;
while(j<=n&&a[i]==a[j])++j;
push(j-i);
}
reverse(dp+1,dp+n+1);
per(i,n,1){
rep(j,i+1,n){
usu(dp[i],mu(dp[j],C(j-1,i-1)));
}
}
printf("%d\n",dp[K+1]);
return 0;
}
Submission Info
Submission Time |
|
Task |
G - Increasing K Times |
User |
xay5421 |
Language |
C++ (GCC 9.2.1) |
Score |
600 |
Code Size |
2336 Byte |
Status |
AC |
Exec Time |
376 ms |
Memory |
3852 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00.txt, example_01.txt |
All |
example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt |
Case Name |
Status |
Exec Time |
Memory |
example_00.txt |
AC |
6 ms |
3692 KiB |
example_01.txt |
AC |
2 ms |
3688 KiB |
test_00.txt |
AC |
376 ms |
3680 KiB |
test_01.txt |
AC |
371 ms |
3852 KiB |
test_02.txt |
AC |
373 ms |
3684 KiB |
test_03.txt |
AC |
2 ms |
3712 KiB |
test_04.txt |
AC |
2 ms |
3628 KiB |
test_05.txt |
AC |
59 ms |
3692 KiB |
test_06.txt |
AC |
94 ms |
3640 KiB |
test_07.txt |
AC |
165 ms |
3588 KiB |
test_08.txt |
AC |
149 ms |
3784 KiB |
test_09.txt |
AC |
14 ms |
3616 KiB |
test_10.txt |
AC |
10 ms |
3636 KiB |
test_11.txt |
AC |
8 ms |
3640 KiB |
test_12.txt |
AC |
160 ms |
3676 KiB |
test_13.txt |
AC |
2 ms |
3772 KiB |
test_14.txt |
AC |
93 ms |
3740 KiB |
test_15.txt |
AC |
5 ms |
3612 KiB |
test_16.txt |
AC |
291 ms |
3852 KiB |
test_17.txt |
AC |
160 ms |
3520 KiB |
test_18.txt |
AC |
45 ms |
3696 KiB |
test_19.txt |
AC |
125 ms |
3788 KiB |
test_20.txt |
AC |
35 ms |
3632 KiB |
test_21.txt |
AC |
5 ms |
3772 KiB |
test_22.txt |
AC |
200 ms |
3584 KiB |
test_23.txt |
AC |
141 ms |
3632 KiB |
test_24.txt |
AC |
7 ms |
3840 KiB |
test_25.txt |
AC |
137 ms |
3684 KiB |
test_26.txt |
AC |
130 ms |
3704 KiB |
test_27.txt |
AC |
129 ms |
3520 KiB |
test_28.txt |
AC |
128 ms |
3644 KiB |
test_29.txt |
AC |
129 ms |
3648 KiB |
test_30.txt |
AC |
151 ms |
3652 KiB |
test_31.txt |
AC |
153 ms |
3684 KiB |
test_32.txt |
AC |
144 ms |
3628 KiB |
test_33.txt |
AC |
144 ms |
3704 KiB |
test_34.txt |
AC |
155 ms |
3648 KiB |