提出 #74715153


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
bool st;
using namespace std;
/*Ctrl+Alt+G F*/
namespace AC{
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 15
#define between ' '
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}void flush(){Fwrite::flush();}}cout;}
#undef Setprecision
using Fastio::cin;
using Fastio::cout;
using Fastio::endl;
using istream=Fastio::Reader;
using ostream=Fastio::Writer;

const int MOD=998244353;
int qpow(int a,int b=MOD-2){
	int res=1;
	a%=MOD;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b/=2;
	}
	return res;
}

int fac[210];
int inv[210];
void init(){
	if(fac[1]!=0)return;
	fac[0]=1;
	inv[0]=1;
	for(int i=1;i<210;i++){
		fac[i]=(fac[i-1]*i)%MOD;
		inv[i]=qpow(fac[i]);
	}
}
void solve(){
	init();
	int n,c;
	cin>>n>>c;
	vector<int>a(n+1);
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a.begin()+1,a.end());
	a.push_back(c+1);
	int invc=qpow(c);
	vector<vector<int>>dp(n+1,vector<int>(n+1,0));
	dp[0][0]=1;
	for(int k=n;k>=1;k--){
		int pk=(a[k+1]-a[k])%MOD*invc%MOD;
		vector<vector<int>>nxt(n+1,vector<int>(n+1,0));
		for(int m=0;m<=n;m++)for(int p=0;p<=m;p++){
			int val=dp[m][p];
			if(val==0)continue;
			if(pk==0){
				int nm=m;
				int np=p==0?0:p-1;
				nxt[nm][np]+=val;
				if(nxt[nm][np]>=MOD)nxt[nm][np]-=MOD;
			}else{
				int pc=1;
				for(int c=0;m+c<=n;c++){
					int nm=m+c;
					int np=(p+c==0)?0:p+c-1;
					int tmp=val*pc%MOD*inv[c]%MOD;
					nxt[nm][np]+=tmp;
					if(nxt[nm][np]>=MOD)nxt[nm][np]-=MOD;
					pc=(pc*pk)%MOD;
				}
			}
		}
		dp=nxt;
	}
	int p0=(a[1]-1)%MOD*invc%MOD;
	vector<int>ans(n+1,0);
	for(int m=0;m<=n;m++){
		int pr=qpow(p0,n-m)*inv[n-m]%MOD*fac[n]%MOD;
		for(int p=0;p<=m;p++){
			if(dp[m][p]==0)continue;
			int S=m-p;
			if(S>=0&&S<=n){
				int tmp=dp[m][p]*pr%MOD;
				ans[S]=(ans[S]+tmp)%MOD;
			}
		}
	}
	for(int i=0;i<=n;i++)cout<<ans[i]<<' ';
	cout<<"\n";
}
}
bool ed;
signed main(){
#ifdef debug
	cerr<<"----------------------------------- START -----------------------------------\n";
#endif
	int t=1;
	cin>>t;
	while(t--)AC::solve();
#ifdef debug
	cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
	AC::cout.flush();
	cerr<<"\n------------------------------------ END ------------------------------------\n";
	cerr<<setprecision(3)<<fixed<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<"               "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<"               "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
#endif
}

提出情報

提出日時
問題 C - Greedy Customers 2
ユーザ nut321
言語 C++23 (GCC 15.2.0)
得点 700
コード長 6178 Byte
結果 AC
実行時間 58 ms
メモリ 3852 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 1
AC × 27
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3524 KiB
01_handmade_00.txt AC 2 ms 3792 KiB
01_handmade_01.txt AC 2 ms 3848 KiB
01_handmade_02.txt AC 58 ms 3808 KiB
01_handmade_03.txt AC 1 ms 3532 KiB
02_random_00.txt AC 1 ms 3604 KiB
02_random_01.txt AC 1 ms 3592 KiB
02_random_02.txt AC 57 ms 3788 KiB
02_random_03.txt AC 58 ms 3852 KiB
02_random_04.txt AC 58 ms 3696 KiB
02_random_05.txt AC 58 ms 3792 KiB
02_random_06.txt AC 58 ms 3740 KiB
02_random_07.txt AC 58 ms 3736 KiB
02_random_08.txt AC 58 ms 3848 KiB
02_random_09.txt AC 58 ms 3780 KiB
02_random_10.txt AC 58 ms 3696 KiB
02_random_11.txt AC 58 ms 3808 KiB
02_random_12.txt AC 58 ms 3816 KiB
02_random_13.txt AC 58 ms 3808 KiB
02_random_14.txt AC 58 ms 3848 KiB
02_random_15.txt AC 10 ms 3740 KiB
02_random_16.txt AC 33 ms 3696 KiB
02_random_17.txt AC 2 ms 3780 KiB
02_random_18.txt AC 37 ms 3780 KiB
02_random_19.txt AC 14 ms 3788 KiB
02_random_20.txt AC 29 ms 3684 KiB
02_random_21.txt AC 18 ms 3756 KiB