結果

問題 No.3153 probability max K
ユーザー Rumain831
提出日時 2025-05-23 13:09:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 653 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 92,920 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-23 13:09:35
合計ジャッジ時間 6,058 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;

ll modpow(ll a, ll b, ll p){
  ll ans=1;
  while(b>0){
    if(b%2==1) ans=(ans*a)%p;
    b/=2;
    a=(a*a)%p;
  }
  return ans;
}

int main(void){
  int n, k; cin >> n >> k;
  ll mod=998244353;
  vector<ll> a(n), rev(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
    rev[i]=modpow(a[i], mod-2, mod);
  }
  auto prob=[&](ll tar){
    if(tar==0) return 0ll;
    ll ans=1;
    for(int i=0; i<n; i++){
      ans*=min(tar, a[i])*rev[i];
      ans%=mod;
    }
    return ans;
  };
  cout << (prob(k)-prob(k-1)+mod)%mod << endl;
  return 0;
}
0