結果

問題 No.856 増える演算
ユーザー 0w10w1
提出日時 2019-08-01 17:46:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,544 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 208,292 KB
実行使用メモリ 16,984 KB
最終ジャッジ日時 2023-09-18 17:40:17
合計ジャッジ時間 13,279 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 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 2 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,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 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 3 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 10 ms
4,380 KB
testcase_35 AC 7 ms
4,380 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 9 ms
4,380 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 6 ms
4,376 KB
testcase_42 AC 11 ms
4,376 KB
testcase_43 AC 5 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 5 ms
4,376 KB
testcase_48 AC 8 ms
4,380 KB
testcase_49 AC 6 ms
4,380 KB
testcase_50 AC 8 ms
4,380 KB
testcase_51 AC 10 ms
4,376 KB
testcase_52 AC 11 ms
4,380 KB
testcase_53 AC 74 ms
16,416 KB
testcase_54 AC 60 ms
15,764 KB
testcase_55 AC 72 ms
16,344 KB
testcase_56 AC 57 ms
15,716 KB
testcase_57 AC 75 ms
16,440 KB
testcase_58 AC 68 ms
16,208 KB
testcase_59 AC 85 ms
16,552 KB
testcase_60 AC 63 ms
16,032 KB
testcase_61 AC 86 ms
16,720 KB
testcase_62 AC 82 ms
16,604 KB
testcase_63 AC 44 ms
16,064 KB
testcase_64 AC 79 ms
16,376 KB
testcase_65 AC 56 ms
15,716 KB
testcase_66 AC 62 ms
15,976 KB
testcase_67 AC 69 ms
16,000 KB
testcase_68 AC 81 ms
16,652 KB
testcase_69 AC 80 ms
16,856 KB
testcase_70 AC 90 ms
16,984 KB
testcase_71 AC 82 ms
16,680 KB
testcase_72 AC 76 ms
16,376 KB
testcase_73 AC 94 ms
16,760 KB
testcase_74 AC 93 ms
16,840 KB
testcase_75 AC 94 ms
16,900 KB
testcase_76 AC 93 ms
16,768 KB
testcase_77 AC 94 ms
16,904 KB
testcase_78 AC 93 ms
16,756 KB
testcase_79 AC 93 ms
16,944 KB
testcase_80 AC 93 ms
16,948 KB
testcase_81 AC 94 ms
16,760 KB
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) {
    ans = 1LL * ans * ipow(A[i], pa[N] - pa[i + 1]) % 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