結果

問題 No.856 増える演算
ユーザー ianCKianCK
提出日時 2020-01-01 03:52:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 122 ms / 3,153 ms
コード長 2,284 bytes
コンパイル時間 1,314 ms
コンパイル使用メモリ 69,916 KB
実行使用メモリ 7,868 KB
最終ジャッジ日時 2023-08-13 10:49:21
合計ジャッジ時間 11,297 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
6,552 KB
testcase_01 AC 51 ms
6,560 KB
testcase_02 AC 50 ms
6,556 KB
testcase_03 AC 50 ms
6,556 KB
testcase_04 AC 49 ms
6,620 KB
testcase_05 AC 50 ms
6,588 KB
testcase_06 AC 50 ms
6,600 KB
testcase_07 AC 49 ms
6,612 KB
testcase_08 AC 50 ms
6,624 KB
testcase_09 AC 49 ms
6,612 KB
testcase_10 AC 50 ms
6,576 KB
testcase_11 AC 50 ms
6,640 KB
testcase_12 AC 51 ms
6,624 KB
testcase_13 AC 50 ms
6,600 KB
testcase_14 AC 50 ms
6,512 KB
testcase_15 AC 50 ms
6,624 KB
testcase_16 AC 49 ms
6,612 KB
testcase_17 AC 49 ms
6,596 KB
testcase_18 AC 50 ms
6,624 KB
testcase_19 AC 49 ms
6,560 KB
testcase_20 AC 50 ms
6,508 KB
testcase_21 AC 49 ms
6,596 KB
testcase_22 AC 50 ms
6,572 KB
testcase_23 AC 52 ms
6,624 KB
testcase_24 AC 52 ms
6,640 KB
testcase_25 AC 50 ms
6,596 KB
testcase_26 AC 50 ms
6,596 KB
testcase_27 AC 49 ms
6,620 KB
testcase_28 AC 52 ms
6,596 KB
testcase_29 AC 52 ms
6,540 KB
testcase_30 AC 51 ms
6,572 KB
testcase_31 AC 50 ms
6,608 KB
testcase_32 AC 52 ms
6,568 KB
testcase_33 AC 54 ms
6,540 KB
testcase_34 AC 58 ms
7,012 KB
testcase_35 AC 55 ms
7,444 KB
testcase_36 AC 57 ms
7,032 KB
testcase_37 AC 56 ms
7,000 KB
testcase_38 AC 50 ms
6,608 KB
testcase_39 AC 51 ms
6,624 KB
testcase_40 AC 53 ms
6,620 KB
testcase_41 AC 53 ms
6,564 KB
testcase_42 AC 60 ms
6,984 KB
testcase_43 AC 53 ms
6,592 KB
testcase_44 AC 50 ms
6,620 KB
testcase_45 AC 51 ms
6,576 KB
testcase_46 AC 54 ms
6,624 KB
testcase_47 AC 53 ms
6,544 KB
testcase_48 AC 55 ms
7,172 KB
testcase_49 AC 54 ms
6,572 KB
testcase_50 AC 57 ms
7,064 KB
testcase_51 AC 58 ms
6,984 KB
testcase_52 AC 59 ms
7,004 KB
testcase_53 AC 85 ms
7,268 KB
testcase_54 AC 70 ms
6,996 KB
testcase_55 AC 82 ms
7,332 KB
testcase_56 AC 68 ms
7,292 KB
testcase_57 AC 87 ms
7,324 KB
testcase_58 AC 79 ms
7,756 KB
testcase_59 AC 98 ms
7,560 KB
testcase_60 AC 72 ms
7,044 KB
testcase_61 AC 100 ms
7,536 KB
testcase_62 AC 87 ms
7,532 KB
testcase_63 AC 55 ms
6,616 KB
testcase_64 AC 91 ms
7,768 KB
testcase_65 AC 65 ms
6,572 KB
testcase_66 AC 73 ms
6,972 KB
testcase_67 AC 81 ms
7,328 KB
testcase_68 AC 88 ms
7,552 KB
testcase_69 AC 89 ms
7,640 KB
testcase_70 AC 102 ms
7,836 KB
testcase_71 AC 92 ms
7,572 KB
testcase_72 AC 86 ms
7,272 KB
testcase_73 AC 104 ms
7,772 KB
testcase_74 AC 98 ms
7,856 KB
testcase_75 AC 97 ms
7,868 KB
testcase_76 AC 97 ms
7,852 KB
testcase_77 AC 102 ms
7,744 KB
testcase_78 AC 96 ms
7,840 KB
testcase_79 AC 99 ms
7,776 KB
testcase_80 AC 106 ms
7,808 KB
testcase_81 AC 108 ms
7,852 KB
testcase_82 AC 122 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <math.h>
#include <complex>
using namespace std;

typedef long long int ll;
constexpr int kMod = int(1E9 + 7), kN = 262144;
constexpr double pi = acos(-1);
constexpr complex<double> one = complex<double>(1, 0), half = complex<double>(0.5, 0);

ll Pow(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % kMod;
		a = a * a % kMod;
		b >>= 1;
	}
	return ans;
}


void FFT(vector<complex<double>> &v, bool on, int sz) {
	complex<double> wn, u, t, w, inv(1.0 / sz, 0);
	for (int i = 1, j = sz >> 1, k; i < (sz - 1); i++) {
		if (i < j) swap(v[i], v[j]);
		k = sz >> 1;
		while (j & k) {
			j ^= k;
			k >>= 1;
		}
		j |= k;
	}
	for (int i = 2; i <= sz; i <<= 1) {
		wn = on ? complex<double>(cos(2 * pi / i), -sin(2 * pi / i)) : complex<double>(cos(2 * pi / i), sin(2 * pi / i));
		for (int j = 0; j < sz; j += i) {
			w = 1;
			for (int k = j; k < j + (i >> 1); k++) {
				u = v[k];
				t = w * v[k + (i >> 1)];
				v[k] = u + t;
				v[k + (i >> 1)] = u - t;
				w *= wn;
			}
		}
	}
	if (on) for (int i = 0; i < sz; i++) v[i] *= inv;

}

int a[kN];
ll ts[kN];

bool Lesser(int ax, int ay, int bx, int by) {
	long double left = (ax + ay), right = (bx + by);
	left *= pow(ax, ay), right *= pow(bx, by);
	return left > right;
}

int main() {
	int n, l, r, nm;
	ll ans = 1, tmp = 1;
	vector<complex<double>> v(kN);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	ts[0] = 0;
	for (int i = 1; i <= n; i++) ts[i] = (ts[i - 1] + a[i]) % (kMod - 1);
	
	for (int i = 1; i <= n; i++) v[a[i]] += one;
	FFT(v, false, kN);
	for (int i = 0; i < kN; i++) v[i] = v[i] * v[i];
	FFT(v, true, kN);
	for (int i = 1; i <= n; i++) v[a[i] << 1] -= one;
	for (int i = 1; i < kN; i++) v[i] *= half;

	
	for (int i = 1; i < kN; i++) tmp = tmp * Pow(i, ll(v[i].real() + 0.5)) % kMod;
	for (int i = 1; i <= n; i++) ans = ans * Pow(a[i], ts[n] - ts[i] + kMod - 1) % kMod;
	
	l = a[n - 1], r = a[n], nm = a[n];
	for (int i = n - 2; i >= 1; i--) {
		nm = min(nm, a[i + 1]);
		if (Lesser(l, r, a[i], nm)) {
			l = a[i];
			r = nm;
		}
	}


	ans = ans * tmp % kMod;
	printf("%lld\n", ans * Pow((l + r) * Pow(l, r) % kMod, kMod - 2) % kMod);
}
0