結果
問題 | No.856 増える演算 |
ユーザー | LayCurse |
提出日時 | 2019-08-21 05:43:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 71 ms / 3,153 ms |
コード長 | 12,304 bytes |
コンパイル時間 | 3,066 ms |
コンパイル使用メモリ | 221,428 KB |
実行使用メモリ | 17,032 KB |
最終ジャッジ日時 | 2024-10-07 15:05:10 |
合計ジャッジ時間 | 9,369 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
15,568 KB |
testcase_01 | AC | 21 ms
15,700 KB |
testcase_02 | AC | 21 ms
15,572 KB |
testcase_03 | AC | 22 ms
15,948 KB |
testcase_04 | AC | 22 ms
15,564 KB |
testcase_05 | AC | 23 ms
15,568 KB |
testcase_06 | AC | 22 ms
14,672 KB |
testcase_07 | AC | 21 ms
14,924 KB |
testcase_08 | AC | 23 ms
15,572 KB |
testcase_09 | AC | 23 ms
15,568 KB |
testcase_10 | AC | 22 ms
14,796 KB |
testcase_11 | AC | 23 ms
15,564 KB |
testcase_12 | AC | 23 ms
15,692 KB |
testcase_13 | AC | 24 ms
14,668 KB |
testcase_14 | AC | 24 ms
15,448 KB |
testcase_15 | AC | 22 ms
15,576 KB |
testcase_16 | AC | 23 ms
15,576 KB |
testcase_17 | AC | 24 ms
15,452 KB |
testcase_18 | AC | 23 ms
15,580 KB |
testcase_19 | AC | 22 ms
16,080 KB |
testcase_20 | AC | 24 ms
15,580 KB |
testcase_21 | AC | 24 ms
15,576 KB |
testcase_22 | AC | 24 ms
15,444 KB |
testcase_23 | AC | 25 ms
14,796 KB |
testcase_24 | AC | 24 ms
15,700 KB |
testcase_25 | AC | 24 ms
15,564 KB |
testcase_26 | AC | 23 ms
15,948 KB |
testcase_27 | AC | 22 ms
16,076 KB |
testcase_28 | AC | 23 ms
14,924 KB |
testcase_29 | AC | 24 ms
15,568 KB |
testcase_30 | AC | 23 ms
15,572 KB |
testcase_31 | AC | 23 ms
16,072 KB |
testcase_32 | AC | 24 ms
14,924 KB |
testcase_33 | AC | 25 ms
14,924 KB |
testcase_34 | AC | 29 ms
15,708 KB |
testcase_35 | AC | 26 ms
16,200 KB |
testcase_36 | AC | 29 ms
15,704 KB |
testcase_37 | AC | 28 ms
15,948 KB |
testcase_38 | AC | 24 ms
15,572 KB |
testcase_39 | AC | 26 ms
14,800 KB |
testcase_40 | AC | 24 ms
15,576 KB |
testcase_41 | AC | 26 ms
15,708 KB |
testcase_42 | AC | 29 ms
16,204 KB |
testcase_43 | AC | 25 ms
15,708 KB |
testcase_44 | AC | 24 ms
15,444 KB |
testcase_45 | AC | 24 ms
14,668 KB |
testcase_46 | AC | 25 ms
16,080 KB |
testcase_47 | AC | 24 ms
15,948 KB |
testcase_48 | AC | 27 ms
16,204 KB |
testcase_49 | AC | 25 ms
14,924 KB |
testcase_50 | AC | 27 ms
15,708 KB |
testcase_51 | AC | 30 ms
15,836 KB |
testcase_52 | AC | 29 ms
15,836 KB |
testcase_53 | AC | 53 ms
16,204 KB |
testcase_54 | AC | 43 ms
16,276 KB |
testcase_55 | AC | 52 ms
16,336 KB |
testcase_56 | AC | 41 ms
14,920 KB |
testcase_57 | AC | 57 ms
16,224 KB |
testcase_58 | AC | 49 ms
16,140 KB |
testcase_59 | AC | 62 ms
16,076 KB |
testcase_60 | AC | 46 ms
15,052 KB |
testcase_61 | AC | 62 ms
15,560 KB |
testcase_62 | AC | 61 ms
16,588 KB |
testcase_63 | AC | 29 ms
15,716 KB |
testcase_64 | AC | 59 ms
16,684 KB |
testcase_65 | AC | 41 ms
16,108 KB |
testcase_66 | AC | 46 ms
16,080 KB |
testcase_67 | AC | 52 ms
16,208 KB |
testcase_68 | AC | 61 ms
16,944 KB |
testcase_69 | AC | 61 ms
15,436 KB |
testcase_70 | AC | 69 ms
15,692 KB |
testcase_71 | AC | 60 ms
16,204 KB |
testcase_72 | AC | 56 ms
16,208 KB |
testcase_73 | AC | 71 ms
15,948 KB |
testcase_74 | AC | 68 ms
15,952 KB |
testcase_75 | AC | 68 ms
15,820 KB |
testcase_76 | AC | 69 ms
15,944 KB |
testcase_77 | AC | 67 ms
16,332 KB |
testcase_78 | AC | 68 ms
16,332 KB |
testcase_79 | AC | 68 ms
17,032 KB |
testcase_80 | AC | 69 ms
16,204 KB |
testcase_81 | AC | 68 ms
16,200 KB |
testcase_82 | AC | 49 ms
16,712 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define MD 1000000007 #define PI 3.14159265358979323846 void *wmem; template<class S, class T> inline S min_L(S a,T b){ return a<=b?a:b; } template<class S, class T> inline S max_L(S a,T b){ return a>=b?a:b; } template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16]={0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } struct mint{ static unsigned R, RR, Rinv, W, md, mdninv; unsigned val; mint(){ } mint(int a){ val = mulR(a); } mint(unsigned a){ val = mulR(a); } mint(long long a){ val = mulR(a); } mint(unsigned long long a){ val = mulR(a); } int get_inv(long long a, int md){ long long e, s=md, t=a, u=1, v=0; while(s){ e=t/s; t-=e*s; u-=e*v; swap(t,s); swap(u,v); } if(u<0){ u+=md; } return u; } void setmod(unsigned m){ int i; unsigned t; W = 32; md = m; R = (1ULL << W) % md; RR = (unsigned long long)R*R % md; switch(m){ case 104857601: Rinv = 2560000; mdninv = 104857599; break; case 998244353: Rinv = 232013824; mdninv = 998244351; break; case 1000000007: Rinv = 518424770; mdninv = 2226617417U; break; case 1000000009: Rinv = 171601999; mdninv = 737024967; break; case 1004535809: Rinv = 234947584; mdninv = 1004535807; break; case 1007681537: Rinv = 236421376; mdninv = 1007681535; break; case 1012924417: Rinv = 238887936; mdninv = 1012924415; break; case 1045430273: Rinv = 254466304; mdninv = 1045430271; break; case 1051721729: Rinv = 257538304; mdninv = 1051721727; break; default: Rinv = get_inv(R, md); mdninv = 0; t = 0; for(i=0;i<((int)W);i++){ if(t%2==0){ t+=md; mdninv |= (1U<<i); } t /= 2; } } } unsigned mulR(unsigned a){ return (unsigned long long)a*R%md; } unsigned mulR(int a){ if(a < 0){ a = a%md+md; } return mulR((unsigned)a); } unsigned mulR(unsigned long long a){ return mulR((unsigned)(a%md)); } unsigned mulR(long long a){ a %= md; if(a < 0){ a += md; } return mulR((unsigned)a); } unsigned reduce(unsigned T){ unsigned m=T * mdninv, t=(unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned reduce(unsigned long long T){ unsigned m=(unsigned)T * mdninv, t=(unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned get(){ return reduce(val); } mint &operator+=(mint a){ val += a.val; if(val >= md){ val -= md; } return *this; } mint &operator-=(mint a){ if(val < a.val){ val = val + md - a.val; } else{ val -= a.val; } return *this; } mint &operator*=(mint a){ val = reduce((unsigned long long)val*a.val); return *this; } mint &operator/=(mint a){ return *this *= a.inverse(); } mint operator+(mint a){ return mint(*this)+=a; } mint operator-(mint a){ return mint(*this)-=a; } mint operator*(mint a){ return mint(*this)*=a; } mint operator/(mint a){ return mint(*this)/=a; } mint operator+(int a){ return mint(*this)+=mint(a); } mint operator-(int a){ return mint(*this)-=mint(a); } mint operator*(int a){ return mint(*this)*=mint(a); } mint operator/(int a){ return mint(*this)/=mint(a); } mint operator+(long long a){ return mint(*this)+=mint(a); } mint operator-(long long a){ return mint(*this)-=mint(a); } mint operator*(long long a){ return mint(*this)*=mint(a); } mint operator/(long long a){ return mint(*this)/=mint(a); } mint operator-(void){ mint res; if(val){ res.val=md-val; } else{ res.val=0; } return res; } operator bool(void){ return val!=0; } operator int(void){ return get(); } operator long long(void){ return get(); } mint inverse(){ int a=val, b=md, t, u=1, v=0; mint res; while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if(u < 0){ u += md; } res.val = (unsigned long long)u*RR % md; return res; } mint pw(unsigned long long b){ mint a(*this), res; res.val = R; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } bool operator==(int a){ return mulR(a)==val; } bool operator!=(int a){ return mulR(a)!=val; } } ; mint operator+(int a, mint b){ return mint(a)+=b; } mint operator-(int a, mint b){ return mint(a)-=b; } mint operator*(int a, mint b){ return mint(a)*=b; } mint operator/(int a, mint b){ return mint(a)/=b; } mint operator+(long long a, mint b){ return mint(a)+=b; } mint operator-(long long a, mint b){ return mint(a)-=b; } mint operator*(long long a, mint b){ return mint(a)*=b; } mint operator/(long long a, mint b){ return mint(a)/=b; } inline void rd(int &x){ int k, m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ char f[10]; int m=0, s=0; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } inline void wt_L(mint x){ int i; i = (int)x; wt_L(i); } template<class T, class S> inline T pow_L(T a, S b){ T res=1; res = 1; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } struct fft_pnt{ double x, y; fft_pnt(void){ } fft_pnt(double a, double b){ x = a; y = b; } void set(double a, double b){ x = a; y = b; } fft_pnt& operator+=(fft_pnt a){ x+=a.x; y+=a.y; return *this; } fft_pnt& operator-=(fft_pnt a){ x-=a.x; y-=a.y; return *this; } fft_pnt& operator*=(fft_pnt a){ fft_pnt p=*this; x = p.x*a.x-p.y*a.y; y = p.x*a.y+p.y*a.x; return *this; } fft_pnt operator+(fft_pnt a){ return fft_pnt(*this) += a; } fft_pnt operator-(fft_pnt a){ return fft_pnt(*this) -= a; } fft_pnt operator*(fft_pnt a){ return fft_pnt(*this) *= a; } } ; void fft_L(int n, fft_pnt x[], void *mem){ double theta=2*PI / n, tmp; fft_pnt a, aa, b, bb, c, cc, d, dd, w1, w2, w3, *y=(fft_pnt*)mem; int i, j, n1, n2, n3, step=1; while(n > 2){ n1 = n / 4; n2 = n1 + n1; n3 = n1 + n2; for(i=0;i<(n1);i++){ w1 = fft_pnt(cos(i*theta),-sin(i*theta)); w2 = w1*w1; w3 = w1*w2; for(j=0;j<(step);j++){ a = x[j+step*i]; b = x[j+step*(i+n1)]; c = x[j+step*(i+n2)]; d = x[j+step*(i+n3)]; aa = a + c; bb = a - c; cc = b + d; dd = b - d; tmp = dd.y; dd.y = dd.x; dd.x = -tmp; y[j+step*(4*i )] = aa + cc; y[j+step*(4*i+1)] = w1*(bb - dd); y[j+step*(4*i+2)] = w2*(aa - cc); y[j+step*(4*i+3)] = w3*(bb + dd); } } n /= 4; step *= 4; theta *= 4; swap(x,y); } if(n==2){ for(i=0;i<(step);i++){ y[i] = x[i] + x[i+step]; y[i+step] = x[i] - x[i+step]; } n /= 2; step *= 2; theta *= 2; swap(x,y); } for(i=0;i<(step);i++){ y[i] = x[i]; } } void fftinv_L(int n, fft_pnt x[], void *mem){ double theta=2*PI / n, tmp; fft_pnt a, aa, b, bb, c, cc, d, dd, w1, w2, w3, *y=(fft_pnt*)mem; int i, j, n1, n2, n3, step=1; while(n > 2){ n1 = n / 4; n2 = n1 + n1; n3 = n1 + n2; for(i=0;i<(n1);i++){ w1 = fft_pnt(cos(i*theta),sin(i*theta)); w2 = w1*w1; w3 = w1*w2; for(j=0;j<(step);j++){ a = x[j+step*i]; b = x[j+step*(i+n1)]; c = x[j+step*(i+n2)]; d = x[j+step*(i+n3)]; aa = a + c; bb = a - c; cc = b + d; dd = b - d; tmp = dd.y; dd.y = dd.x; dd.x = -tmp; y[j+step*(4*i )] = aa + cc; y[j+step*(4*i+1)] = w1*(bb + dd); y[j+step*(4*i+2)] = w2*(aa - cc); y[j+step*(4*i+3)] = w3*(bb - dd); } } n /= 4; step *= 4; theta *= 4; swap(x,y); } if(n==2){ for(i=0;i<(step);i++){ y[i] = x[i] + x[i+step]; y[i+step] = x[i] - x[i+step]; } n /= 2; step *= 2; theta *= 2; swap(x,y); } for(i=0;i<(step);i++){ y[i] = x[i]; } } void convolution_L(double A[], int As, double B[], int Bs, double res[], int Rs, void *mem = wmem){ double mul; fft_pnt *a, *b; int i, n, n2; n =max_L(As+Bs, Rs); for(n2=1;n2<n;n2*=2){ ; } walloc1d(&a, n2, &mem); walloc1d(&b, n2, &mem); for(i=0;i<(As);i++){ a[i].set(A[i], 0); } for(i=(As);i<(n2);i++){ a[i].set(0,0); } for(i=0;i<(Bs);i++){ b[i].set(B[i], 0); } for(i=(Bs);i<(n2);i++){ b[i].set(0,0); } fft_L(n2, a, mem); fft_L(n2, b, mem); for(i=0;i<(n2);i++){ a[i] *= b[i]; } fftinv_L(n2, a, mem); mul = 1.0 / n2; for(i=0;i<(Rs);i++){ res[i] = a[i].x * mul; } } void convolution_L(double A[], int As, double res[], int Rs, void *mem = wmem){ double mul; fft_pnt *a; int i, n, n2; n =max_L(As+As, Rs); for(n2=1;n2<n;n2*=2){ ; } walloc1d(&a, n2, &mem); for(i=0;i<(As);i++){ a[i].set(A[i], 0); } for(i=(As);i<(n2);i++){ a[i].set(0,0); } fft_L(n2, a, mem); for(i=0;i<(n2);i++){ a[i] *= a[i]; } fftinv_L(n2, a, mem); mul = 1.0 / n2; for(i=0;i<(Rs);i++){ res[i] = a[i].x * mul; } } char memarr[96000000]; unsigned mint::R, mint::RR, mint::Rinv, mint::W, mint::md, mint::mdninv; int N; int A[100000]; double c[100001]; double cnv[200001]; long long s[100001]; int mn[100001]; int main(){ double dmin, dtmp; int i; long long tk; mint res, tmp; wmem = memarr; { mint x; x.setmod(MD); } rd(N); { int Lj4PdHRW; for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } res = 1; for(i=0;i<(N);i++){ c[A[i]]++; } convolution_L(c, 100001, cnv, 200001); for(i=0;i<(N);i++){ cnv[2*A[i]]--; } for(i=0;i<(200001);i++){ tk = (long long)(cnv[i]/2 + 0.5); if(tk){ res *= (pow_L(mint(i),tk)); } } for(i=N-1;i>=0;i--){ s[i] = s[i+1] + A[i]; } for(i=0;i<(N);i++){ res *= (pow_L(mint(A[i]),s[i+1])); } mn[N] = 1073709056; for(i=N-1;i>=0;i--){ mn[i] =min_L(mn[i+1], A[i]); } dmin = 1e300; for(i=N-2;i>=0;i--){ dtmp = log(A[i] + mn[i+1]) + log(A[i]) * mn[i+1]; if(dtmp < dmin){ dmin = dtmp; tmp = (A[i] + mn[i+1]) * (pow_L(mint(A[i]),mn[i+1])); } } res /= tmp; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190820-1 // --- original code --- // int N, A[1d5]; // // double c[100001], cnv[200001]; // ll s[100001]; // int mn[100001]; // { // int i; // ll tk; // mint res, tmp; // double dmin, dtmp; // // rd(N,A(N)); // // res = 1; // // rep(i,N) c[A[i]]++; // convolution(c, 100001, cnv, 200001); // rep(i,N) cnv[2A[i]]--; // // rep(i,200001){ // tk = (ll)(cnv[i]/2 + 0.5); // if(tk) res *= (mint(i) ** tk); // } // // for(i=N-1;i>=0;i--) s[i] = s[i+1] + A[i]; // rep(i,N) res *= (mint(A[i]) ** s[i+1]); // // mn[N] = int_inf; // for(i=N-1;i>=0;i--) mn[i] = min(mn[i+1], A[i]); // // dmin = 1e300; // for(i=N-2;i>=0;i--){ // dtmp = log(A[i] + mn[i+1]) + log(A[i]) * mn[i+1]; // if(dtmp < dmin){ // dmin = dtmp; // tmp = (A[i] + mn[i+1]) * ( mint(A[i]) ** mn[i+1] ); // } // } // // res /= tmp; // wt(res); // }