結果
| 問題 |
No.856 増える演算
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-07-26 22:43:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,116 bytes |
| コンパイル時間 | 2,610 ms |
| コンパイル使用メモリ | 188,836 KB |
| 実行使用メモリ | 34,140 KB |
| 最終ジャッジ日時 | 2024-07-02 08:36:21 |
| 合計ジャッジ時間 | 12,481 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 79 WA * 1 |
コンパイルメッセージ
main.cpp:11:10: warning: 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: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
38 | M pow(auto n) const {
| ^~~~
main.cpp:44:22: warning: 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: warning: 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: warning: 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: warning: 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: warning: 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: warning: 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); }
| ^~~~
ソースコード
#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<int K = 15> void multiply(V<Mint>& a, V<Mint> b) {
if (a.empty() or b.empty()) {
a = {};
return;
}
int n = 1 << __lg(2 * (a.size() + b.size() - 1) - 1);
V<C> f(n), g(n);
for (int i = 0; i < n; ++i) {
if (i < (int) a.size()) f[i].real(a[i].v & ~(~0 << K)), f[i].imag(a[i].v >> K);
if (i < (int) b.size()) g[i].real(b[i].v & ~(~0 << K)), g[i].imag(b[i].v >> K);
}
fft(f), fft(g);
V<C> Al(n), Au(n), Bl(n), Bu(n);
for (int i = 0; i < n; ++i) {
Al[i] = (f[i] + conj(f[-i & n - 1])) / C(2, 0);
Au[i] = (f[i] - conj(f[-i & n - 1])) / C(0, 2);
Bl[i] = (g[i] + conj(g[-i & n - 1])) / C(2, 0);
Bu[i] = (g[i] - conj(g[-i & n - 1])) / C(0, 2);
}
for (int i = 0; i < n; ++i) {
f[i] = Al[i] * Bl[i] + C(0, 1) * Al[i] * Bu[i];
g[i] = Au[i] * Bl[i] + C(0, 1) * Au[i] * Bu[i];
}
fft(f, true), fft(g, true);
a.resize(a.size() + b.size() - 1);
for (int i = 0; i < (int) a.size(); ++i) {
lint l = real(f[i]) / n + 0.5;
lint m = (imag(f[i]) + real(g[i])) / n + 0.5;
lint u = imag(g[i]) / n + 0.5;
a[i] = l + m * Mint(1 << K) + u * Mint(1 << 2 * K);
}
}
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<Mint> 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);
}
}
{
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';
}
risujiroh