結果

問題 No.856 増える演算
ユーザー risujirohrisujiroh
提出日時 2019-07-26 22:46:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 3,153 ms
コード長 4,629 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 181,704 KB
実行使用メモリ 14,460 KB
最終ジャッジ日時 2023-09-15 03:21:19
合計ジャッジ時間 9,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
13,868 KB
testcase_01 AC 36 ms
13,780 KB
testcase_02 AC 37 ms
13,792 KB
testcase_03 AC 37 ms
13,768 KB
testcase_04 AC 37 ms
13,768 KB
testcase_05 AC 36 ms
13,756 KB
testcase_06 AC 36 ms
13,836 KB
testcase_07 AC 37 ms
13,772 KB
testcase_08 AC 37 ms
13,820 KB
testcase_09 AC 37 ms
13,804 KB
testcase_10 AC 36 ms
13,856 KB
testcase_11 AC 36 ms
13,784 KB
testcase_12 AC 37 ms
13,796 KB
testcase_13 AC 36 ms
13,828 KB
testcase_14 AC 37 ms
13,772 KB
testcase_15 AC 37 ms
13,764 KB
testcase_16 AC 36 ms
13,856 KB
testcase_17 AC 36 ms
13,780 KB
testcase_18 AC 37 ms
13,772 KB
testcase_19 AC 36 ms
13,880 KB
testcase_20 AC 37 ms
13,880 KB
testcase_21 AC 36 ms
13,816 KB
testcase_22 AC 37 ms
13,836 KB
testcase_23 AC 38 ms
13,780 KB
testcase_24 AC 37 ms
13,772 KB
testcase_25 AC 37 ms
13,776 KB
testcase_26 AC 35 ms
13,876 KB
testcase_27 AC 36 ms
13,772 KB
testcase_28 AC 37 ms
13,828 KB
testcase_29 AC 37 ms
13,832 KB
testcase_30 AC 38 ms
13,856 KB
testcase_31 AC 36 ms
13,876 KB
testcase_32 AC 38 ms
13,832 KB
testcase_33 AC 40 ms
14,044 KB
testcase_34 AC 44 ms
14,104 KB
testcase_35 AC 41 ms
14,100 KB
testcase_36 AC 44 ms
14,036 KB
testcase_37 AC 42 ms
14,088 KB
testcase_38 AC 36 ms
13,824 KB
testcase_39 AC 39 ms
13,768 KB
testcase_40 AC 39 ms
14,092 KB
testcase_41 AC 40 ms
14,144 KB
testcase_42 AC 45 ms
14,036 KB
testcase_43 AC 39 ms
14,116 KB
testcase_44 AC 37 ms
13,832 KB
testcase_45 AC 37 ms
13,768 KB
testcase_46 AC 40 ms
14,032 KB
testcase_47 AC 39 ms
14,120 KB
testcase_48 AC 42 ms
14,148 KB
testcase_49 AC 40 ms
14,096 KB
testcase_50 AC 42 ms
14,016 KB
testcase_51 AC 44 ms
14,096 KB
testcase_52 AC 44 ms
14,084 KB
testcase_53 AC 68 ms
14,032 KB
testcase_54 AC 56 ms
14,312 KB
testcase_55 AC 68 ms
14,044 KB
testcase_56 AC 54 ms
14,064 KB
testcase_57 AC 69 ms
14,116 KB
testcase_58 AC 62 ms
14,076 KB
testcase_59 AC 78 ms
14,284 KB
testcase_60 AC 59 ms
14,020 KB
testcase_61 AC 80 ms
14,300 KB
testcase_62 AC 82 ms
14,140 KB
testcase_63 AC 40 ms
13,756 KB
testcase_64 AC 72 ms
14,088 KB
testcase_65 AC 52 ms
14,036 KB
testcase_66 AC 59 ms
14,144 KB
testcase_67 AC 65 ms
14,096 KB
testcase_68 AC 74 ms
14,044 KB
testcase_69 AC 73 ms
14,096 KB
testcase_70 AC 81 ms
14,300 KB
testcase_71 AC 77 ms
14,096 KB
testcase_72 AC 71 ms
14,036 KB
testcase_73 AC 86 ms
14,420 KB
testcase_74 AC 86 ms
14,400 KB
testcase_75 AC 85 ms
14,460 KB
testcase_76 AC 86 ms
14,300 KB
testcase_77 AC 85 ms
14,312 KB
testcase_78 AC 85 ms
14,356 KB
testcase_79 AC 85 ms
14,296 KB
testcase_80 AC 85 ms
14,408 KB
testcase_81 AC 86 ms
14,344 KB
testcase_82 AC 68 ms
14,308 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:10: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   11 |   ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
      |          ^~~~
main.cpp:38:9: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   38 |   M pow(auto n) const {
      |         ^~~~
main.cpp:44:22: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   44 |   friend M operator*(auto l, M r) { return M(l) *= r; }
      |                      ^~~~
main.cpp:45:22: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   45 |   friend M operator/(auto l, M r) { return M(l) /= r; }
      |                      ^~~~
main.cpp:46:22: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   46 |   friend M operator+(auto l, M r) { return M(l) += r; }
      |                      ^~~~
main.cpp:47:22: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   47 |   friend M operator-(auto l, M r) { return M(l) -= r; }
      |                      ^~~~
main.cpp:50:26: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   50 |   friend bool operator==(auto l, M r) { return M(l) == r; }
      |                          ^~~~
main.cpp:51:26: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   51 |   friend bool operator!=(auto l, M r) { return !(l == r); }
      |                          ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned)1e9 + 7>;

using R = double;
constexpr R pi = acos((R) -1);
using C = complex<R>;
C& operator*=(C& l, const C& r) {
  return l = {real(l) * real(r) - imag(l) * imag(r), real(l) * imag(r) + imag(l) * real(r)};
}
void fft(V<C>& a, bool inv = false) {
  int n = a.size();
  int j = 0;
  for (int i = 1; i < n; ++i) {
    int w = n >> 1;
    while (j >= w) j -= w, w >>= 1;
    j += w;
    if (i < j) swap(a[i], a[j]);
  }
  static VV<C> xi(30);
  for (int k = 0; 1 << k < n; ++k) if (xi[k].empty()) {
    xi[k].resize(1 << k);
    for (int i = 0; i < 1 << k; ++i) {
      xi[k][i] = polar<R>(1, i * pi / (1 << k));
    }
  }
  for (int k = 0; 1 << k < n; ++k) {
    const int w = 1 << k;
    for (int s = 0; s < n; s += 2 * w) {
      for (int i = s; i < s + w; ++i) {
        j = i + w;
        a[j] *= inv ? conj(xi[k][i - s]) : xi[k][i - s];
        tie(a[i], a[j]) = make_pair(a[i] + a[j], a[i] - a[j]);
      }
    }
  }
}
template<class Z> void multiply(V<Z>& a, const V<Z>& b) {
  assert(!a.empty() and !b.empty());
  int n = 1 << __lg(2 * (a.size() + b.size() - 1) - 1);
  V<C> c(n);
  for (int i = 0; i < n; ++i) {
    if (i < (int) a.size()) c[i].real(a[i]);
    if (i < (int) b.size()) c[i].imag(b[i]);
  }
  fft(c);
  for (int i = 0; i <= n / 2; ++i) {
    c[i] *= c[i];
    if (i & n / 2 - 1) c[n - i] *= c[n - i];
    c[i] = C(0, -0.25) * (c[i] - conj(c[n - i & n - 1]));
    if (i & n / 2 - 1) c[n - i] = conj(c[i]);
  }
  fft(c, true);
  a.resize(a.size() + b.size() - 1);
  for (int i = 0; i < (int) a.size(); ++i) {
    a[i] = real(c[i]) / n + 0.5;
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  Mint res = 1;
  {
    V<lint> c(1e5 + 1);
    for (int e : a) c[e] += 1;
    multiply(c, c);
    for (int e : a) c[2 * e] -= 1;
    for (auto&& e : c) e /= 2;
    for (int i = 2; i <= 2e5; ++i) if (c[i]) {
      res *= Mint(i).pow(c[i]);
    }
  }
  {
    V<lint> c(n + 1);
    for (int i = n - 1; i >= 0; --i) c[i] += a[i] + c[i + 1];
    for (int i = 0; i < n; ++i) {
      res *= Mint(a[i]).pow(c[i + 1]);
    }
  }
  {
    auto mn = a;
    for (int i = n - 2; i >= 0; --i) mn[i] = min(a[i], mn[i + 1]);
    int mi = -1;
    {
      long double x = 1e10;
      for (int i = 0; i < n - 1; ++i) {
        long double curr = log((long double)a[i] + mn[i + 1]) + mn[i + 1] * log((long double)a[i]);
        if (curr < x) {
          x = curr;
          mi = i;
        }
      }
    }
    res /= (a[mi] + mn[mi + 1]) * Mint(a[mi]).pow(mn[mi + 1]);
  }
  cout << res << '\n';
}
0