結果

問題 No.856 増える演算
ユーザー kotamanegikotamanegi
提出日時 2019-07-26 22:54:00
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,941 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 205,560 KB
実行使用メモリ 52,868 KB
最終ジャッジ日時 2024-11-30 14:27:58
合計ジャッジ時間 26,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 5 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 722 ms
52,740 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