結果

問題 No.856 増える演算
ユーザー 0w10w1
提出日時 2019-08-01 15:44:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,566 bytes
コンパイル時間 2,559 ms
コンパイル使用メモリ 209,120 KB
実行使用メモリ 21,440 KB
最終ジャッジ日時 2023-09-18 17:24:33
合計ジャッジ時間 12,003 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
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 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 3 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef complex<double> cpx;
const double PI = acos(-1);
vector<cpx> FFT(vector<cpx> P, bool inv = 0) {
  assert(__builtin_popcount(P.size()) == 1);
  int lg = 31 - __builtin_clz(P.size()), n = 1 << lg;  // == P.size();
  for (int j = 1, i = 0; j < n - 1; ++j) {
    for (int k = n >> 1; k > (i ^= k); k >>= 1)
      ;
    if (j < i) swap(P[i], P[j]);
  }                                                   // bit reverse
  auto w1 = exp((2 - 4 * inv) * PI / n * cpx(0, 1));  // order is 1<<lg
  for (int i = 1; i <= lg; ++i) {
    auto wn = pow(w1, 1 << (lg - i));  // order is 1<<i
    for (int k = 0; k < (1 << lg); k += 1 << i) {
      cpx base = 1;
      for (int j = 0; j < (1 << i - 1); ++j, base = base * wn) {
        auto t = base * P[k + j + (1 << i - 1)];
        auto u = P[k + j];
        P[k + j] = u + t;
        P[k + j + (1 << i - 1)] = u - t;
      }
    }
  }
  if (inv)
    for (int i = 0; i < n; ++i) P[i] /= n;
  return P;
}

const int M = 1e9 + 7;

int ipow(int v, int64_t n, int m = M) {
  int r = 1;
  while (n) {
    if (n & 1) r = 1LL * r * v % m;
    v = 1LL * v * v % m;
    n >>= 1;
  }
  return r;
}

int inv(int v, int m = M) {
  return ipow(v, m - 2, m);
}

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

  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  pair<int, int> dnr(A[0], A[1]);
  for (int i = N - 2, minp = A[N - 1]; ~i; --i) {
    auto log_eval = [](int x, int y) {
      return log(x + y) + y * log(x);
    };
    if (log_eval(A[i], minp), log_eval(dnr.first, dnr.second)) {
      dnr = make_pair(A[i], minp);
    }
    minp = min(minp, A[i]);
  }

  vector<int64_t> pa(N + 1);
  for (int i = 0; i < N; ++i) {
    pa[i + 1] = pa[i] + A[i];
  }

  int maxa = *max_element(A.begin(), A.end());
  int maxa2 = maxa * 2 + 1; while (__builtin_popcount(maxa2) != 1) ++maxa2;

  vector<cpx> c(maxa2);
  for (int a : A) c[a] += 1.0;
  vector<cpx> fc = FFT(c);
  for (int i = 0; i < fc.size(); ++i) {
    fc[i] *= fc[i];
  }
  vector<cpx> c2 = FFT(fc, true);

  int ans = 1;

  for (int s = 2; s < maxa * 2 + 1; ++s) {
    int64_t cs = int(real(c2[s]) + 0.5) / 2;
    if (~s & 1) cs -= int(real(c[s / 2]) + 0.5) / 2;
    ans = 1LL * ans * ipow(s, cs) % M;
  }

  for (int i = 0; i + 1 < N; ++i) {
    int sp = (pa[N] - pa[i + 1]) % M;
    ans = 1LL * ans * ipow(A[i], sp) % M;
  }

  int idnr = inv(1LL * (dnr.first + dnr.second) % M * ipow(dnr.first, dnr.second) % M);
  ans = 1LL * ans * idnr % M;

  cout << ans << endl;

  return 0;
}
0