結果

問題 No.856 増える演算
ユーザー kotamanegikotamanegi
提出日時 2019-07-26 22:54:26
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 691 ms / 3,153 ms
コード長 3,939 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 172,896 KB
実行使用メモリ 52,720 KB
最終ジャッジ日時 2023-08-20 12:42:35
合計ジャッジ時間 23,975 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 5 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 9 ms
4,380 KB
testcase_34 AC 16 ms
4,696 KB
testcase_35 AC 12 ms
4,516 KB
testcase_36 AC 15 ms
4,560 KB
testcase_37 AC 14 ms
4,596 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 6 ms
4,376 KB
testcase_40 AC 8 ms
4,376 KB
testcase_41 AC 9 ms
4,376 KB
testcase_42 AC 16 ms
4,672 KB
testcase_43 AC 8 ms
4,380 KB
testcase_44 AC 5 ms
4,380 KB
testcase_45 AC 7 ms
4,380 KB
testcase_46 AC 9 ms
4,380 KB
testcase_47 AC 8 ms
4,380 KB
testcase_48 AC 13 ms
4,504 KB
testcase_49 AC 9 ms
4,376 KB
testcase_50 AC 12 ms
4,444 KB
testcase_51 AC 15 ms
4,536 KB
testcase_52 AC 16 ms
4,748 KB
testcase_53 AC 640 ms
52,204 KB
testcase_54 AC 623 ms
52,012 KB
testcase_55 AC 643 ms
52,244 KB
testcase_56 AC 623 ms
51,968 KB
testcase_57 AC 641 ms
52,216 KB
testcase_58 AC 648 ms
52,160 KB
testcase_59 AC 680 ms
52,404 KB
testcase_60 AC 628 ms
52,076 KB
testcase_61 AC 663 ms
52,380 KB
testcase_62 AC 647 ms
52,380 KB
testcase_63 AC 597 ms
52,512 KB
testcase_64 AC 654 ms
52,236 KB
testcase_65 AC 612 ms
51,920 KB
testcase_66 AC 624 ms
51,860 KB
testcase_67 AC 631 ms
52,196 KB
testcase_68 AC 644 ms
52,324 KB
testcase_69 AC 641 ms
52,292 KB
testcase_70 AC 666 ms
52,560 KB
testcase_71 AC 649 ms
52,340 KB
testcase_72 AC 644 ms
52,148 KB
testcase_73 AC 669 ms
52,704 KB
testcase_74 AC 662 ms
52,640 KB
testcase_75 AC 670 ms
52,628 KB
testcase_76 AC 691 ms
52,556 KB
testcase_77 AC 668 ms
52,576 KB
testcase_78 AC 654 ms
52,592 KB
testcase_79 AC 670 ms
52,720 KB
testcase_80 AC 663 ms
52,632 KB
testcase_81 AC 670 ms
52,632 KB
testcase_82 AC 654 ms
52,556 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