結果
問題 |
No.3153 probability max K
|
ユーザー |
|
提出日時 | 2025-05-20 22:06:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 2,048 bytes |
コンパイル時間 | 1,781 ms |
コンパイル使用メモリ | 198,152 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-20 22:06:32 |
合計ジャッジ時間 | 4,882 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main(){ ll n,k; cin>>n>>k; vl a(n); rep(i,n) cin>>a[i]; ll all_prod=1; rep(i,n) { all_prod*=a[i]; all_prod%=mod; } ll pdinv=modinv(all_prod,mod); auto funk=[&](ll f) { ll res=1; rep(i,n) { res*=(min(f,a[i])); res%=mod; } res*=pdinv; res%=mod; return res; }; ll ans=funk(k)-funk(k-1); if(ans<0) ans+=mod; cout<<ans<<nl; } /////// library zone /////// #else #include <bits/stdc++.h> #include <atcoder/segtree> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define srep(i,l,r) for(ll i=l;i<=r;i++) using ll = long long; using ld = long double; const ll mod=998244353; #define vout(v) for(auto i :v) cout<<i<<" "; #define INF 9223300000000000000ll #define Winf 5e12 #define nl "\n" #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define vl vector<ll> #define vc vector<char> ll op(ll a,ll b) {return a+b;} ll e() {return 0ll;} template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} void no() { cout<<"No"<<nl;} void yes() { cout<<"Yes"<<nl;} void yn(bool a) { cout<<(a ? "Yes":"No")<<nl; } ll sum(vector<ll>& a) { ll ans=0; for(auto i:a) ans+=i; return ans; } ll modpow(ll fl, ll po, ll mode) { // mode: 0=modなし, 1=modあり ll ret=1; if (mode) { while (po>0) { if (po&1) ret=(ret*fl)%mod; fl=(fl*fl)%mod; po>>=1; } } else { while (po>0) { if(po&1) ret*=fl; fl*=fl; po>>=1; } } return ret; } ll modinv(ll a, ll mod) { //拡張Euclidによるmodでの逆元, a*u+mod*v=1を解く ll b=mod,u=1,v=0; while (b) { ll t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } u%=mod; if (u < 0) u+=mod; return u; } #endif