結果

問題 No.766 金魚すくい
ユーザー 0w10w1
提出日時 2020-11-14 21:47:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,140 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 205,356 KB
実行使用メモリ 5,124 KB
最終ジャッジ日時 2023-09-30 06:35:54
合計ジャッジ時間 5,891 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 36 ms
4,976 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 36 ms
4,900 KB
testcase_38 AC 36 ms
4,916 KB
testcase_39 AC 36 ms
4,928 KB
testcase_40 AC 35 ms
4,812 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 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];
  }

  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