結果

問題 No.856 増える演算
ユーザー pekempeypekempey
提出日時 2019-07-26 22:25:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 3,153 ms
コード長 5,008 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 179,780 KB
実行使用メモリ 63,300 KB
最終ジャッジ日時 2023-09-15 02:12:14
合計ジャッジ時間 14,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
63,056 KB
testcase_01 AC 92 ms
62,744 KB
testcase_02 AC 97 ms
62,800 KB
testcase_03 AC 99 ms
62,708 KB
testcase_04 AC 96 ms
62,688 KB
testcase_05 AC 96 ms
62,688 KB
testcase_06 AC 97 ms
62,712 KB
testcase_07 AC 97 ms
62,696 KB
testcase_08 AC 97 ms
62,712 KB
testcase_09 AC 96 ms
63,036 KB
testcase_10 AC 97 ms
62,652 KB
testcase_11 AC 98 ms
62,652 KB
testcase_12 AC 98 ms
62,656 KB
testcase_13 AC 97 ms
62,728 KB
testcase_14 AC 98 ms
62,844 KB
testcase_15 AC 96 ms
62,656 KB
testcase_16 AC 98 ms
62,740 KB
testcase_17 AC 97 ms
62,656 KB
testcase_18 AC 97 ms
62,688 KB
testcase_19 AC 97 ms
62,644 KB
testcase_20 AC 98 ms
62,692 KB
testcase_21 AC 97 ms
62,708 KB
testcase_22 AC 98 ms
62,844 KB
testcase_23 AC 100 ms
62,848 KB
testcase_24 AC 101 ms
62,656 KB
testcase_25 AC 97 ms
62,896 KB
testcase_26 AC 96 ms
62,744 KB
testcase_27 AC 96 ms
62,796 KB
testcase_28 AC 97 ms
62,736 KB
testcase_29 AC 97 ms
62,704 KB
testcase_30 AC 96 ms
62,676 KB
testcase_31 AC 97 ms
62,708 KB
testcase_32 AC 98 ms
62,716 KB
testcase_33 AC 101 ms
62,740 KB
testcase_34 AC 107 ms
62,736 KB
testcase_35 AC 104 ms
62,844 KB
testcase_36 AC 109 ms
62,736 KB
testcase_37 AC 112 ms
62,660 KB
testcase_38 AC 99 ms
62,816 KB
testcase_39 AC 99 ms
62,712 KB
testcase_40 AC 103 ms
62,844 KB
testcase_41 AC 100 ms
62,764 KB
testcase_42 AC 107 ms
62,760 KB
testcase_43 AC 99 ms
62,692 KB
testcase_44 AC 96 ms
62,848 KB
testcase_45 AC 97 ms
62,700 KB
testcase_46 AC 100 ms
62,716 KB
testcase_47 AC 100 ms
62,804 KB
testcase_48 AC 105 ms
62,740 KB
testcase_49 AC 101 ms
62,652 KB
testcase_50 AC 103 ms
62,760 KB
testcase_51 AC 108 ms
62,824 KB
testcase_52 AC 108 ms
62,660 KB
testcase_53 AC 136 ms
62,728 KB
testcase_54 AC 120 ms
62,692 KB
testcase_55 AC 137 ms
63,076 KB
testcase_56 AC 117 ms
62,760 KB
testcase_57 AC 137 ms
63,004 KB
testcase_58 AC 127 ms
62,808 KB
testcase_59 AC 153 ms
62,920 KB
testcase_60 AC 122 ms
62,704 KB
testcase_61 AC 153 ms
63,028 KB
testcase_62 AC 150 ms
63,136 KB
testcase_63 AC 100 ms
63,028 KB
testcase_64 AC 146 ms
62,912 KB
testcase_65 AC 113 ms
62,848 KB
testcase_66 AC 123 ms
62,652 KB
testcase_67 AC 131 ms
62,736 KB
testcase_68 AC 146 ms
63,292 KB
testcase_69 AC 145 ms
62,944 KB
testcase_70 AC 154 ms
62,968 KB
testcase_71 AC 147 ms
62,992 KB
testcase_72 AC 140 ms
63,300 KB
testcase_73 AC 168 ms
63,144 KB
testcase_74 AC 163 ms
63,160 KB
testcase_75 AC 163 ms
63,080 KB
testcase_76 AC 163 ms
63,136 KB
testcase_77 AC 161 ms
63,148 KB
testcase_78 AC 163 ms
63,056 KB
testcase_79 AC 165 ms
62,944 KB
testcase_80 AC 160 ms
62,992 KB
testcase_81 AC 164 ms
62,916 KB
testcase_82 AC 148 ms
63,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

template<int N>
class FFT {
  using C = complex<double>;
  C rots[N];

public:
  FFT() {
    const double pi = acos(-1);
    for (int i = 0; i < N / 2; i++) {
      rots[i + N / 2].real(cos(2 * pi / N * i));
      rots[i + N / 2].imag(sin(2 * pi / N * i));
    }
    for (int i = N / 2 - 1; i >= 1; i--) {
      rots[i] = rots[i * 2];
    }
  }

private:
  inline static C mul(C x, C y) {
    return C(x.real() * y.real() - x.imag() * y.imag(), x.real() * y.imag() + x.imag() * y.real());
  }

  void fft(vector<C> &a, bool rev) {
    const int n = a.size();
    int i = 0;
    for (int j = 1; j < n - 1; j++) {
      for (int k = n >> 1; k > (i ^= k); k >>= 1);
      if (j < i) swap(a[i], a[j]);
    }
    for (int i = 1; i < n; i *= 2) {
      for (int j = 0; j < n; j += i * 2) {
        for (int k = 0; k < i; k++) {
          C s = a[j + k + 0];
          C t = mul(a[j + k + i], rots[i + k]);
          a[j + k + 0] = s + t;
          a[j + k + i] = s - t;
        }
      }
    }
    if (rev) {
      reverse(a.begin() + 1, a.end());
      for (int i = 0; i < n; i++) {
        a[i] *= 1.0 / n;
      }
    }
  }

public:
  vector<long long> convolution(vector<long long> a, vector<long long> b) {
    int t = 1;
    while (t < a.size() + b.size() - 1) t *= 2;
    vector<C> z(t);
    for (int i = 0; i < a.size(); i++) z[i].real(a[i]);
    for (int i = 0; i < b.size(); i++) z[i].imag(b[i]);
    fft(z, false);
    vector<C> w(t);
    for (int i = 0; i < t; i++) {
      C p = (z[i] + conj(z[(t - i) % t])) * C(0.5, 0);
      C q = (z[i] - conj(z[(t - i) % t])) * C(0, -0.5);
      w[i] = p * q;
    }
    fft(w, true);
    vector<long long> ans(a.size() + b.size() - 1);
    for (int i = 0; i < ans.size(); i++) {
      ans[i] = round(w[i].real());
    }
    return ans;
  }

  vector<mint> convolution(vector<mint> a, vector<mint> b) {
    int t = 1;
    while (t < a.size() + b.size() - 1) t *= 2;
    vector<C> A(t), B(t);
    for (int i = 0; i < a.size(); i++) A[i] = C((int)a[i] & 0x7fff, (int)a[i] >> 15);
    for (int i = 0; i < b.size(); i++) B[i] = C((int)b[i] & 0x7fff, (int)b[i] >> 15);
    fft(A, false);
    fft(B, false);
    vector<C> X(t), Y(t);
    for (int i = 0; i < t; i++) {
      int j = (t - i) % t;
      C AL = (A[i] + conj(A[j])) * C(0.5, 0);
      C AH = (A[i] - conj(A[j])) * C(0, -0.5);
      C BL = (B[i] + conj(B[j])) * C(0.5, 0);
      C BH = (B[i] - conj(B[j])) * C(0, -0.5);
      X[i] = AL * BL + AH * BL * C(0, 1);
      Y[i] = AL * BH + AH * BH * C(0, 1);
    }
    fft(X, true);
    fft(Y, true);
    vector<mint> ans(a.size() + b.size() - 1);
    for (int i = 0; i < ans.size(); i++) {
      long long l = (long long)round(X[i].real()) % MOD;
      long long m = ((long long)round(X[i].imag()) + (long long)round(Y[i].real())) % MOD;
      long long h = (long long)round(Y[i].imag()) % MOD;
      ans[i] = (l + (m << 15) + (h << 30)) % MOD;
    }
    return ans;
  }
};

mint modinv(mint n) {
  int a = (int)n;
  int b = MOD;
  int s = 1;
  int t = 0;
  while (b != 0) {
    int q = a / b;
    a -= q * b;
    s -= q * t;
    swap(a, b);
    swap(s, t);
  }
  if (s < 0) s += MOD;
  return s;
}

mint modpow(mint a, long long b) {
  mint res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}


FFT<1 << 21> fft;

int main() {
  int n;
  cin >> n;
  vector<ll> f(1<<18);
  vector<int> a(n);
  rep(i, n) cin >> a[i], f[a[i]]++;
  f = fft.convolution(f, f);
  rep(i, n) f[2*a[i]]--;
  mint ans = 1;
  rep(i, 1 << 18) ans *= modpow(i, f[i] / 2);
  ll s = 0;
  rep(i, n) s += a[i];
  rep(i, n) {
    s -= a[i];
    ans *= modpow(a[i], s);
  }
  tuple<double, int, int> mn(1e100, 0, 0);
  int r = a[n-1];
  repr(i, n-1) {
    mn = min(mn, make_tuple(log(a[i] + r) + r * log(a[i]), a[i], r));
    r = min(r, a[i]);
  }
  ans *= modinv((get<1>(mn) + get<2>(mn)) * modpow(get<1>(mn), get<2>(mn)));
  cout << ans << endl;
}
0