結果

問題 No.995 タピオカオイシクナーレ
ユーザー utouto97utouto97
提出日時 2020-02-21 22:35:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,629 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 169,296 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-07-30 06:29:18
合計ジャッジ時間 3,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 39 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 39 ms
4,380 KB
testcase_21 AC 40 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 40 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  */
const int mod = 1e9 + 7;

int mpow(int a, int b) {
  if (b == 0)
    return 1;
  return mpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod;
}

int e[42][2];

signed main() {
  int n, m, k, p, q;
  cin >> n >> m >> k >> p >> q;

  V<int> b(n);
  rep(i, 0, n) cin >> b[i];

  e[0][0] = p * mpow(q, mod - 2) % mod;
  e[0][1] = (1 - p * mpow(q, mod - 2) % mod + mod) % mod;

  rep(i, 1, 42) {
    int x = e[i - 1][0];
    int y = e[i - 1][1];
    e[i][0] = (x * x % mod + y * y % mod) % mod;
    e[i][1] = 2 * x % mod * y % mod;
  }

  V<int> cnt(2, -1);
  int i = 0;
  while (k) {
    if (k % 2) {
      int x = e[i][0];
      int y = e[i][1];
      if (cnt[0] == -1) {
        cnt[0] = x;
        cnt[1] = y;
      } else {
        int t = cnt[0];
        int s = cnt[1];

        cnt[0] = (x * t % mod + y * s % mod) % mod;
        cnt[1] = (x * s % mod + y * t % mod) % mod;
      }
    }

    k /= 2;
    i++;
  }

  V<int> sum(2);
  rep(i, 0, m) (sum[0] += b[i]) %= mod;;
  rep(i, m, n) (sum[1] += b[i]) %= mod;;

  int ans = 0;
  (ans += sum[0] * cnt[0] % mod) %= mod;
  (ans += sum[1] * cnt[1] % mod) %= mod;
  cout << ans << endl;

  return 0;
}
0