結果
問題 | No.2468 Mercurialist |
ユーザー | Yerin Jung |
提出日時 | 2023-09-23 23:59:23 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 999 bytes |
コンパイル時間 | 1,313 ms |
コンパイル使用メモリ | 164,948 KB |
実行使用メモリ | 8,324 KB |
最終ジャッジ日時 | 2023-09-23 23:59:27 |
合計ジャッジ時間 | 3,447 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
8,228 KB |
testcase_01 | AC | 6 ms
8,056 KB |
testcase_02 | AC | 6 ms
8,148 KB |
testcase_03 | AC | 27 ms
8,260 KB |
testcase_04 | AC | 21 ms
8,164 KB |
testcase_05 | AC | 33 ms
8,056 KB |
testcase_06 | AC | 6 ms
8,124 KB |
testcase_07 | AC | 6 ms
8,056 KB |
testcase_08 | AC | 21 ms
8,112 KB |
testcase_09 | AC | 5 ms
8,048 KB |
testcase_10 | AC | 20 ms
8,300 KB |
testcase_11 | AC | 6 ms
8,256 KB |
testcase_12 | AC | 6 ms
8,052 KB |
testcase_13 | AC | 5 ms
8,056 KB |
testcase_14 | AC | 21 ms
8,104 KB |
testcase_15 | AC | 6 ms
8,044 KB |
testcase_16 | AC | 6 ms
8,056 KB |
testcase_17 | AC | 6 ms
8,084 KB |
testcase_18 | AC | 12 ms
8,100 KB |
testcase_19 | AC | 13 ms
8,044 KB |
testcase_20 | AC | 17 ms
8,080 KB |
testcase_21 | AC | 23 ms
8,188 KB |
testcase_22 | AC | 6 ms
8,084 KB |
testcase_23 | AC | 8 ms
8,048 KB |
testcase_24 | AC | 9 ms
8,148 KB |
testcase_25 | AC | 9 ms
8,060 KB |
testcase_26 | AC | 10 ms
8,124 KB |
testcase_27 | AC | 8 ms
8,128 KB |
testcase_28 | AC | 20 ms
8,324 KB |
testcase_29 | AC | 8 ms
8,060 KB |
testcase_30 | AC | 7 ms
8,316 KB |
testcase_31 | AC | 16 ms
8,308 KB |
testcase_32 | AC | 11 ms
8,084 KB |
testcase_33 | AC | 13 ms
8,148 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second const ll mod=998244353; const int N=3e5+5; const int iu=3e5; ll x,y,z,k; ll f[N],inf[N]; ll pw(ll x,ll y){ if(y==0) return 1; if(y%2) return x*pw(x,y-1)%mod; ll res=pw(x,y/2); return res*res%mod; } ll C(ll x,ll y){ return f[x]*inf[x-y]%mod*inf[y]%mod; } int main(){ ios::sync_with_stdio(false);cin.tie(0); cin >> x >> y >> z >> k; f[0]=1; for(int i=1; i<=iu ;i++) f[i]=f[i-1]*i%mod; inf[iu]=pw(f[iu],mod-2); for(int i=iu; i>=1 ;i--) inf[i-1]=inf[i]*i%mod; ll n=x+y+z; ll tot=C(x+y+z,x)*C(y+z,y)%mod*f[y]%mod; ll cum=0; for(int i=1; i<=n-x+1 ;i++){ ll frog=C(n-i,x-1); ll ways=0; int st=i-k; if(st<=0) ways=f[y+z]*inf[z]%mod; else if(st<=y) ways=pw(n-i-x+k+1,st)*f[y+z-st]%mod*inf[z]%mod; else ways=pw(n-i-x+k+1,y); cum=(cum+frog*ways)%mod; //cout << i << ' ' << frog << ' ' << ways << ' ' << n-i-x+k+1 << endl;; } cum=cum*pw(tot,mod-2)%mod; cout << cum << '\n'; }