結果
問題 |
No.3153 probability max K
|
ユーザー |
|
提出日時 | 2025-05-20 21:29:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 156 ms / 2,000 ms |
コード長 | 2,270 bytes |
コンパイル時間 | 1,533 ms |
コンパイル使用メモリ | 194,996 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-05-20 21:29:31 |
合計ジャッジ時間 | 5,571 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; //入力が必ず-mod<a<modの時. struct mint{ long long v = 0; mint(){} mint(int a){v = a<0?a+mod:a;} mint(long long a){v = a<0?a+mod:a;} mint(unsigned long long a){v = a;} long long val(){return v;} void modu(){v %= mod;} mint &operator=(const mint &b) = default; mint operator-()const{return mint(0)-(*this);} mint operator+(const mint b)const{return mint(v)+=b;} mint operator-(const mint b)const{return mint(v)-=b;} mint operator*(const mint b)const{return mint(v)*=b;} mint operator/(const mint b)const{return mint(v)/=b;} mint operator+=(const mint b){ v += b.v; if(v >= mod) v -= mod; return *this; } mint operator-=(const mint b){ v -= b.v; if(v < 0) v += mod; return *this; } mint operator*=(const mint b){v = v*b.v%mod; return *this;} mint operator/=(mint b){ if(b == 0) assert(false); int left = mod-2; while(left){if(left&1) *this *= b; b *= b; left >>= 1;} return *this; } mint operator++(){*this += 1; return *this;} mint operator--(){*this -= 1; return *this;} mint operator++(int){*this += 1; return *this;} mint operator--(int){*this -= 1; return *this;} bool operator==(const mint b)const{return v == b.v;} bool operator!=(const mint b)const{return v != b.v;} bool operator>(const mint b)const{return v > b.v;} bool operator>=(const mint b)const{return v >= b.v;} bool operator<(const mint b)const{return v < b.v;} bool operator<=(const mint b)const{return v <= b.v;} mint pow(long long n)const{ mint ret = 1,p = v; if(n < 0) p = p.inv(),n = -n; while(n){ if(n&1) ret *= p; p *= p; n >>= 1; } return ret; } mint inv()const{return mint(1)/v;} }; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin >> N >> K; mint ng = 1,ok = 0; while(N--){ int a; cin >> a; mint div = mint(1)/a,n0 = 0,n1 = 0; if(K <= a) n1 += ng*div; n1 += div*min(K,a)*ok; n0 += div*min(K-1,a)*ng; ng = n0,ok = n1; } cout << ok.v << endl; }