結果

問題 No.766 金魚すくい
ユーザー 0w10w1
提出日時 2020-11-14 21:48:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 1,500 ms
コード長 2,203 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 207,112 KB
実行使用メモリ 5,108 KB
最終ジャッジ日時 2023-09-30 06:36:01
合計ジャッジ時間 4,715 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 40 ms
4,824 KB
testcase_24 AC 39 ms
4,908 KB
testcase_25 AC 43 ms
5,004 KB
testcase_26 AC 38 ms
5,044 KB
testcase_27 AC 41 ms
4,876 KB
testcase_28 AC 39 ms
4,888 KB
testcase_29 AC 39 ms
4,876 KB
testcase_30 AC 39 ms
5,004 KB
testcase_31 AC 41 ms
4,904 KB
testcase_32 AC 39 ms
4,816 KB
testcase_33 AC 36 ms
4,376 KB
testcase_34 AC 38 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 40 ms
4,964 KB
testcase_38 AC 39 ms
5,108 KB
testcase_39 AC 41 ms
4,880 KB
testcase_40 AC 38 ms
4,832 KB
testcase_41 AC 34 ms
4,832 KB
testcase_42 AC 31 ms
4,964 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<int m>
struct Mint {
  int v;
  Mint(int _v = 0) : v(_v) { v %= m; adjust(); }
  void adjust() { if (v < 0) v += m; if (v >= m) v -= m; assert(0 <= v && v < m); }
  Mint operator+() const { return *this; }
  Mint operator-() const { Mint r = Mint(0) - *this; return r.adjust(), r; }
  friend Mint operator+(Mint a, Mint b) { a.v += b.v; return a.adjust(), a; }
  Mint& operator+=(const Mint &b) { return v += b.v, adjust(), *this; }
  friend Mint operator-(Mint a, Mint b) { a.v -= b.v; return a.adjust(), a; }
  Mint& operator-=(const Mint &b) { return v -= b.v, adjust(), *this; }
  friend Mint operator*(Mint a, Mint b) { a.v = (int64_t) a.v * b.v % m; return a.adjust(), a; }
  friend Mint operator*(Mint a, int v) { return a * Mint(v); }
  friend Mint operator^(Mint a, int p) {
    int v = a.v;
    int r = 1;
    for (int i = p; i; i >>= 1) {
      if (i & 1) r = (int64_t) r * v % m;
      v = (int64_t) v * v % m;
    }
    return r;
  }
  friend Mint operator^(Mint a, Mint p) { return a^p.v; }
  friend Mint operator/(Mint a, Mint b) { return a * (Mint(b.v)^(m-2)); }
  friend ostream& operator<<(ostream &os, Mint a) { return os << a.v, os; }
};

int main() {
  ios::sync_with_stdio(false);

  int N, M, P; {
    cin >> N >> M >> P;
  }

  vector<int> V(N); {
    for (int i = 0; i < N; ++i) cin >> V[i];
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
  }

  const int MOD = 1e9 + 7;

  vector<Mint<MOD>> fac(N + M + 1); {
    fac[0] = Mint<MOD>(1);
    for (int i = 1; i <= N + M; ++i) fac[i] = fac[i - 1] * i;
  }

  vector<Mint<MOD>> ifac(N + M + 1); {
    ifac[N + M] = Mint<MOD>(1) / fac[N + M];
    for (int i = N + M; i; --i) ifac[i - 1] = ifac[i] * i;
  }

  auto binomial = [&](int n, int m) { return fac[n] * ifac[m] * ifac[n - m]; };

  Mint<MOD> res; {
    Mint<MOD> p_fail = Mint<MOD>(P) / Mint<MOD>(100) ^ M;
    Mint<MOD> p_succ(1);
    Mint<MOD> p_sum;
    for (int i = 0; i < N; ++i) {
      p_sum = p_sum + binomial(M - 1 + i, M - 1) * p_succ * p_fail;
      p_succ = p_succ * (Mint<MOD>(100 - P) / Mint<MOD>(100));
      res = res + (Mint<MOD>(1) - p_sum) * V[i];
    }
  }

  cout << res << endl;
}
0