結果

問題 No.766 金魚すくい
ユーザー ei1333333
提出日時 2018-11-24 02:30:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,028 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 200,204 KB
最終ジャッジ日時 2025-01-06 17:34:51
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 TLE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

template< int mod >
struct Combination {
  vector< int64_t > mfact, rfact;

  Combination(int sz) : mfact(sz + 1), rfact(sz + 1) {
    mfact[0] = 1;
    for(int i = 1; i < mfact.size(); i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for(int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }

  int64_t fact(int k) const {
    return (mfact[k]);
  }

  int64_t pow(int64_t x, int64_t n) const {
    int64_t ret = 1;
    while(n > 0) {
      if(n & 1) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int64_t inv(int64_t x) const {
    return (pow(x, mod - 2));
  }

  int64_t P(int n, int r) const {
    if(r < 0 || n < r) return (0);
    return (mfact[n] * rfact[n - r] % mod);
  }

  int64_t C(int p, int q) const {
    if(q < 0 || p < q) return (0);
    return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
  }

  int64_t H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return (r == 0 ? 1 : C(n + r - 1, r));
  }
};

int main() {
  int N, M, P;
  cin >> N >> M >> P;
  vector< int > V(N);
  for(int i = 0; i < N; i++) cin >> V[i];
  sort(begin(V), end(V));
  reverse(begin(V), end(V));
  Combination< mod > uku(0);
  int P1 = 1LL * P * uku.inv(100) % mod;
  P = 100 - P;
  int P2 = 1LL * P * uku.inv(100) % mod;

  vector< int > dp(M + 1);
  dp[0] = 1;
  int ret = 0, sum = 0, rest = 1;

  int XX = uku.pow(P1, M), YY = 1;
  for(int i = 0; i < N; i++) {

    for(int j = 1; j <= M; j++) {
      dp[j] += dp[j - 1];
      if(dp[j] >= mod) dp[j] -= mod;
    }

    ret += 1LL * dp[M] * sum % mod * XX % mod * YY % mod;
    if(ret >= mod) ret -= mod;
    rest += mod - 1LL * dp[M] * XX % mod * YY % mod;
    if(rest >= mod) rest -= mod;
    dp[M] = 0;
    sum += V[i];
    if(sum >= mod) sum -= mod;
    YY = 1LL * YY * P2 % mod;
  }
  ret += 1LL * sum * rest % mod;
  if(ret >= mod) ret -= mod;
  cout << ret << endl;
}
0