結果

問題 No.1939 Numbered Colorful Balls
ユーザー leukocyteleukocyte
提出日時 2022-07-02 10:06:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 167,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 01:07:28
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
4,356 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 17 ms
4,356 KB
testcase_03 AC 68 ms
4,360 KB
testcase_04 AC 2 ms
4,360 KB
testcase_05 AC 67 ms
4,356 KB
testcase_06 AC 18 ms
4,356 KB
testcase_07 AC 9 ms
4,356 KB
testcase_08 AC 5 ms
4,352 KB
testcase_09 AC 30 ms
4,356 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 13 ms
4,352 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 14 ms
4,352 KB
testcase_15 AC 7 ms
4,360 KB
testcase_16 AC 31 ms
4,352 KB
testcase_17 AC 20 ms
4,380 KB
testcase_18 AC 14 ms
4,352 KB
testcase_19 AC 30 ms
4,356 KB
testcase_20 AC 8 ms
4,356 KB
testcase_21 AC 21 ms
4,356 KB
testcase_22 AC 3 ms
4,356 KB
testcase_23 AC 10 ms
4,356 KB
testcase_24 AC 20 ms
4,352 KB
testcase_25 AC 10 ms
4,356 KB
testcase_26 AC 57 ms
4,356 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 12 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5;
const int mod=998244353;
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int ksm(ll x,int tp,int s=1){
	for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
	return s;
}
int n,m;
int l[N+5];
int f[N+5];
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&l[i]);
	sort(l+1,l+1+m);
	f[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m&&l[j]<=i;j++)
			f[i]=(f[i]+1ll*l[j]*f[i-l[j]])%mod;
		f[i]=1ll*f[i]*(n+1)%mod;
		for(int j=1;j<=m&&l[j]<=i;j++)
			f[i]=(f[i]-1ll*(i-l[j])*f[i-l[j]])%mod;
		f[i]=ksm(i,mod-2,f[i]+mod);
	}
	printf("%d\n",ksm(n+1,mod-2,f[n]));
	return 0;
}
0