結果

問題 No.856 増える演算
ユーザー 👑 kmjpkmjp
提出日時 2019-07-26 22:48:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 291 ms / 3,153 ms
コード長 2,387 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 174,408 KB
実行使用メモリ 38,804 KB
最終ジャッジ日時 2023-09-15 03:27:07
合計ジャッジ時間 20,142 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
35,988 KB
testcase_01 AC 122 ms
36,044 KB
testcase_02 AC 121 ms
35,996 KB
testcase_03 AC 120 ms
36,392 KB
testcase_04 AC 120 ms
36,004 KB
testcase_05 AC 120 ms
35,988 KB
testcase_06 AC 121 ms
36,004 KB
testcase_07 AC 122 ms
36,020 KB
testcase_08 AC 122 ms
36,256 KB
testcase_09 AC 123 ms
36,024 KB
testcase_10 AC 124 ms
36,312 KB
testcase_11 AC 122 ms
36,016 KB
testcase_12 AC 126 ms
36,216 KB
testcase_13 AC 125 ms
36,016 KB
testcase_14 AC 122 ms
35,996 KB
testcase_15 AC 122 ms
36,140 KB
testcase_16 AC 121 ms
36,216 KB
testcase_17 AC 122 ms
36,264 KB
testcase_18 AC 122 ms
36,256 KB
testcase_19 AC 122 ms
36,100 KB
testcase_20 AC 123 ms
36,216 KB
testcase_21 AC 122 ms
35,992 KB
testcase_22 AC 122 ms
36,072 KB
testcase_23 AC 125 ms
36,248 KB
testcase_24 AC 126 ms
36,200 KB
testcase_25 AC 122 ms
36,360 KB
testcase_26 AC 121 ms
36,000 KB
testcase_27 AC 123 ms
36,024 KB
testcase_28 AC 124 ms
36,152 KB
testcase_29 AC 122 ms
36,332 KB
testcase_30 AC 126 ms
36,372 KB
testcase_31 AC 125 ms
36,124 KB
testcase_32 AC 129 ms
36,196 KB
testcase_33 AC 133 ms
36,520 KB
testcase_34 AC 147 ms
36,992 KB
testcase_35 AC 137 ms
36,540 KB
testcase_36 AC 143 ms
36,684 KB
testcase_37 AC 142 ms
36,664 KB
testcase_38 AC 127 ms
36,120 KB
testcase_39 AC 125 ms
36,440 KB
testcase_40 AC 131 ms
36,440 KB
testcase_41 AC 134 ms
36,348 KB
testcase_42 AC 148 ms
36,712 KB
testcase_43 AC 131 ms
36,236 KB
testcase_44 AC 122 ms
36,212 KB
testcase_45 AC 125 ms
36,428 KB
testcase_46 AC 132 ms
36,476 KB
testcase_47 AC 133 ms
36,360 KB
testcase_48 AC 136 ms
36,504 KB
testcase_49 AC 135 ms
36,436 KB
testcase_50 AC 137 ms
36,504 KB
testcase_51 AC 144 ms
36,732 KB
testcase_52 AC 145 ms
36,744 KB
testcase_53 AC 232 ms
37,228 KB
testcase_54 AC 191 ms
36,720 KB
testcase_55 AC 232 ms
37,392 KB
testcase_56 AC 186 ms
36,620 KB
testcase_57 AC 235 ms
37,532 KB
testcase_58 AC 213 ms
36,960 KB
testcase_59 AC 264 ms
37,864 KB
testcase_60 AC 202 ms
36,692 KB
testcase_61 AC 264 ms
38,072 KB
testcase_62 AC 254 ms
37,820 KB
testcase_63 AC 137 ms
36,296 KB
testcase_64 AC 244 ms
37,492 KB
testcase_65 AC 176 ms
36,540 KB
testcase_66 AC 198 ms
36,684 KB
testcase_67 AC 220 ms
37,088 KB
testcase_68 AC 251 ms
37,712 KB
testcase_69 AC 255 ms
37,696 KB
testcase_70 AC 280 ms
38,120 KB
testcase_71 AC 256 ms
37,912 KB
testcase_72 AC 240 ms
37,624 KB
testcase_73 AC 287 ms
38,484 KB
testcase_74 AC 288 ms
38,392 KB
testcase_75 AC 291 ms
38,396 KB
testcase_76 AC 286 ms
38,336 KB
testcase_77 AC 287 ms
38,804 KB
testcase_78 AC 289 ms
38,792 KB
testcase_79 AC 288 ms
38,348 KB
testcase_80 AC 287 ms
38,468 KB
testcase_81 AC 291 ms
38,564 KB
testcase_82 AC 218 ms
38,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


typedef complex<double> Comp;

vector<Comp> fft(vector<Comp> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		double deg=(rev?-1:1) * 2*acos(-1)/m;
		Comp wr(cos(deg),sin(deg));
		for(i=0;i<n;i+=m) {
			Comp w(1,0);
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				Comp t1=v[j1],t2=w*v[j2];
				v[j1]=t1+t2, v[j2]=t1-t2;
				w*=wr;
			}
		}
	}
	if(rev) FOR(i,n) v[i]*=1.0/n;
	return v;
}

vector<Comp> MultPoly(vector<Comp> P,vector<Comp> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]*=Q[i];
	return fft(P,true);
}

int N;
ll A[101010];
ll S[101010];
ll mi[101010];
ll mo=1000000007;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

double hoge(int a,int b) {
	return log(a+b)+b*log(a);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	FOR(i,N) {
		cin>>A[i];
		S[i+1]=S[i]+A[i];
	}
	
	ll a=1<<20,b=1<<20;
	
	mi[N-1]=A[N-1];
	for(i=N-2;i>=0;i--) {
		mi[i]=min(mi[i+1],A[i]);
		if(hoge(A[i],mi[i+1])<hoge(a,b)) {
			a=A[i];
			b=mi[i+1];
		}
	}
	
	
	
	ll ret=1;
	FOR(i,N) {
		ll sum=S[N]-S[i+1];
		(ret*=modpow(A[i],sum))%=mo;
		
	}
	vector<Comp> D(1<<19);
	FOR(i,N) D[A[i]]+=1;
	auto E=MultPoly(D,D);
	for(i=1;i<=200000;i++) {
		ll x=E[i].real()+0.1;
		if(i%2==0) x=x-D[i/2].real()+0.1;
		x/=2;
		ret=ret*modpow(i,x)%mo;
	}
	(ret*=modpow((a+b)*modpow(a,b)%mo))%=mo;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0