結果

問題 No.1681 +-*
ユーザー ππ
提出日時 2021-09-17 23:09:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,150 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 78,744 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 09:13:08
合計ジャッジ時間 2,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 AC 46 ms
4,380 KB
testcase_14 AC 91 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <limits>
#include <array>

#define FOR(i, s, n) for(auto i = (s); i < n; ++i)
#define REP(i, n) FOR(i, decltype(n)(), n)

using ll = long long;
constexpr ll mod = 1000000007;

template <class T, T b>
class pow_preproc {
  using array_t = std::array<T, std::numeric_limits<T>::digits>;
  static constexpr array_t get_dp() {
    array_t dp = {b % mod};
    FOR(i, 1, std::numeric_limits<T>::digits) {
      dp[i] = (dp[i - 1] * dp[i - 1]) % mod;
    }
    return dp;
  }
  static constexpr array_t _dp = get_dp();
public:
  static constexpr T get_pow(T x) {
    if(x < 0) return 0;
    T y = 1;
    for(int i = 0; x; ++i) {
      if(x % 2) {
        y *= _dp[i];
        y %= mod;
      }
      x /= 2;
    }
    return y;
  }
};

std::array<int, 200001> a = {};
using pow3 = pow_preproc<ll, 3>;

int main() {
  int n;
  ll sum = 0;
  ll muls = 1;
  std::cin >> n;
  REP(i, n) {
    ll a;
    std::cin >> a;
    muls *= a; muls %= mod;
    ll p = pow3::get_pow(n - i - 2);
    if(p <= 0) p = 1;
    else {
      p *= 2;
      p %= mod;
    }
    sum += muls * p; if(sum > mod) sum -= mod;
  }
  std::cout << sum << '\n';
}
0