結果

問題 No.856 増える演算
ユーザー kotamanegikotamanegi
提出日時 2019-07-26 22:54:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 766 ms / 3,153 ms
コード長 3,939 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 204,792 KB
実行使用メモリ 52,856 KB
最終ジャッジ日時 2024-05-07 19:19:23
合計ジャッジ時間 27,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 6 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 11 ms
5,376 KB
testcase_34 AC 17 ms
5,376 KB
testcase_35 AC 13 ms
5,376 KB
testcase_36 AC 17 ms
5,376 KB
testcase_37 AC 15 ms
5,376 KB
testcase_38 AC 6 ms
5,376 KB
testcase_39 AC 7 ms
5,376 KB
testcase_40 AC 10 ms
5,376 KB
testcase_41 AC 10 ms
5,376 KB
testcase_42 AC 19 ms
5,376 KB
testcase_43 AC 10 ms
5,376 KB
testcase_44 AC 5 ms
5,376 KB
testcase_45 AC 7 ms
5,376 KB
testcase_46 AC 11 ms
5,376 KB
testcase_47 AC 9 ms
5,376 KB
testcase_48 AC 13 ms
5,376 KB
testcase_49 AC 11 ms
5,376 KB
testcase_50 AC 14 ms
5,376 KB
testcase_51 AC 17 ms
5,376 KB
testcase_52 AC 17 ms
5,376 KB
testcase_53 AC 731 ms
52,232 KB
testcase_54 AC 712 ms
52,008 KB
testcase_55 AC 722 ms
52,348 KB
testcase_56 AC 701 ms
52,104 KB
testcase_57 AC 728 ms
52,268 KB
testcase_58 AC 728 ms
52,264 KB
testcase_59 AC 742 ms
52,452 KB
testcase_60 AC 705 ms
52,056 KB
testcase_61 AC 736 ms
52,596 KB
testcase_62 AC 735 ms
52,512 KB
testcase_63 AC 704 ms
52,856 KB
testcase_64 AC 733 ms
52,336 KB
testcase_65 AC 703 ms
51,940 KB
testcase_66 AC 712 ms
52,056 KB
testcase_67 AC 732 ms
52,168 KB
testcase_68 AC 732 ms
52,376 KB
testcase_69 AC 735 ms
52,480 KB
testcase_70 AC 744 ms
52,532 KB
testcase_71 AC 737 ms
52,396 KB
testcase_72 AC 730 ms
52,408 KB
testcase_73 AC 754 ms
52,524 KB
testcase_74 AC 758 ms
52,552 KB
testcase_75 AC 766 ms
52,736 KB
testcase_76 AC 754 ms
52,616 KB
testcase_77 AC 751 ms
52,616 KB
testcase_78 AC 753 ms
52,740 KB
testcase_79 AC 755 ms
52,616 KB
testcase_80 AC 757 ms
52,612 KB
testcase_81 AC 750 ms
52,612 KB
testcase_82 AC 737 ms
52,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<complex<double>>  DFT(vector<complex<double>> a) {
	int n = a.size();
	if (n == 1) return a;
	vector<complex<double>> a0(n / 2), a1(n / 2);
	REP(i, n) {
		if (i % 2 == 0) {
			a0[i / 2] = a[i];
		}
		else {
			a1[i / 2] = a[i];
		}
	}
	vector<complex<double>> inversed_a0 = DFT(a0), inversed_a1 = DFT(a1);
	vector<complex<double>> inversed_a(n);
	for (int i = 0; i < n; ++i) {
		complex<double> zeta = complex<double>(cos(2 * Ma_PI * i / n), sin(2 * Ma_PI * i / n));
		inversed_a[i] = inversed_a0[i % (n / 2)] + zeta * inversed_a1[i % (n / 2)];
	}
	return inversed_a;
}
vector<complex<double>> IDFT(vector<complex<double>> inversed_a) {
	int n = inversed_a.size();
	vector<complex<double>> now = DFT(inversed_a);
	reverse(now.begin(), now.end());
	for (int q = now.size() - 1; q >= 1; --q) {
		swap(now[q], now[q - 1]);
	}
	REP(i, n) {
		now[i] /= complex<double>(n, 0);
	}
	return now;
}
vector<complex<double>> conv(vector<complex<double>> a, vector<complex<double>> b) {
	int deg = a.size() + b.size() - 1;
	int n = 1;
	while (n < deg) n <<= 1;
	a.resize(n);
	b.resize(n);
	vector<complex<double>> inversed_a = DFT(a), inversed_b = DFT(b);
	vector<complex<double>> inversed_c(n);
	REP(i, n) {
		inversed_c[i] = inversed_a[i] * inversed_b[i];
	}
	return IDFT(inversed_c);
}
long long powing(long long now,long long hoge) {
	long long ans = 1;
	while (hoge != 0) {
		if (hoge % 2 == 1) {
			ans *= now;
			ans %= MOD;
		}
		hoge /= 2;
		now *= now;
		now %= MOD;
	}
	return ans;
}
long long inv(long long now) {
	return powing(now, MAX_MOD - 2LL);
}
pair<long long,long long> minnest[200000];
int main() {
	long long n;
	cin >> n;
	vector<long long> inputs;
	long long nya = 0;
	REP(i, n) {
		long long a;
		cin >> a;
		nya = max(nya, a);
		inputs.push_back(a);
	}
	vector<complex<double>> a;
	for (int i = 0; i <= nya; ++i) {
		a.push_back(complex<double>());
	}
	REP(i, n) {
		a[inputs[i]] += complex<double>(1.0,0.0);
	}
	vector<complex<double>> now = conv(a, a);
	REP(i, n) {
		now[inputs[i] * 2] -= complex<double>(1.0, 0.0);
	}
	long long ans = 1;
	for (int i = 2; i < now.size(); ++i) {
		long long cnt = round(now[i].real());
		cnt /= 2;
		ans *= powing(i, cnt);
		ans %= MAX_MOD;
	}
	long long cnt = 0;
	for (int i = 0; i < n; ++i) {
		cnt += inputs[i];
	}
	for (int i = 0; i < n; ++i) {
		cnt -= inputs[i];
		ans *= powing(inputs[i], cnt);
		ans %= MAX_MOD;
	}
	minnest[n].first = 1000000;
	for (int i = n - 1; i >= 0; --i) {
		if (inputs[i] < minnest[i+1].first) {
			minnest[i] = make_pair(inputs[i], i);
		}
		else {
			minnest[i] = minnest[i + 1];
		}
	}
	long double bobo = LONG_INF;
	pair<long long, long long>tmp;
	for (int i = 0; i < n-1; ++i) {
		long double geko = log10(inputs[i] + minnest[i+1].first) + log10(inputs[i]) * (long double)minnest[i+1].first;
		if (bobo > geko) {
			bobo = geko;
			tmp = make_pair(i, minnest[i + 1].second);
		}
	}
	ans *= inv(inputs[tmp.first] + inputs[tmp.second]);
	ans %= MAX_MOD;
	ans *= inv(powing(inputs[tmp.first], inputs[tmp.second]));
	ans %= MAX_MOD;
	cout << ans << endl;
	return 0;
}
0