結果
問題 | No.829 成長関数インフレ中 |
ユーザー | kopricky |
提出日時 | 2018-12-07 01:47:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,598 bytes |
コンパイル時間 | 1,990 ms |
コンパイル使用メモリ | 183,476 KB |
実行使用メモリ | 54,592 KB |
最終ジャッジ日時 | 2024-09-15 13:22:18 |
合計ジャッジ時間 | 8,742 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
20,864 KB |
testcase_01 | AC | 13 ms
15,360 KB |
testcase_02 | AC | 13 ms
15,488 KB |
testcase_03 | AC | 13 ms
15,232 KB |
testcase_04 | AC | 14 ms
15,488 KB |
testcase_05 | AC | 14 ms
15,360 KB |
testcase_06 | AC | 14 ms
15,360 KB |
testcase_07 | AC | 13 ms
15,488 KB |
testcase_08 | AC | 13 ms
15,488 KB |
testcase_09 | AC | 13 ms
15,616 KB |
testcase_10 | AC | 13 ms
15,488 KB |
testcase_11 | AC | 14 ms
15,488 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | TLE | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
ソースコード
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx") #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl #define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl #define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl #define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl #define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl #define double long double using namespace std; typedef pair<int,int> P; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 200000; #define getchar getchar_unlocked inline int in() { int n = 0; short c; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } int inv[MAX_N],fac[MAX_N],finv[MAX_N]; void make() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i=2;i<MAX_N;i++){ inv[i] = MOD - (ll)inv[MOD%i] * (MOD/i) % MOD; fac[i] = (ll)fac[i-1] * i % MOD; finv[i] = (ll)finv[i-1] * inv[i] % MOD; } } inline int prod(int a, int b) { return (a < b) ? 0 : ((ll)fac[a] * finv[a-b] % MOD); } void extgcd(int a,int b, int& x,int& y) { if(b){ extgcd(b, a%b, y, x); y -= (a/b)*x; }else{ x = 1, y = 0; } } int mod_inverse(int a, int m) { int x, y; extgcd(a,m,x,y); return (m + x % m) % m; } inline int mod_pow(int a, int n, int mod){ int ret = 1; while(n){ if(n & 1) ret = (ll)ret * a % mod; a = (ll)a * a % mod; n >>= 1; } return ret; } const double PI = acos(-1); complex<double> operator* (const complex<double> a, const complex<double> b){ return complex<double>(a.real()*b.real()-a.imag()*b.imag(),a.real()*b.imag()+a.imag()*b.real()); } vector<complex<double> > fft(vector<complex<double> > a,bool rev = false) { int n = a.size(),h = 0; for(int i = 0; 1 << i < n; i++) h++; //バタフライ演算前の係数の並び替え rep(i,n){ int j = 0; rep(k,h){ j |= (i >> k & 1) << (h-1-k); } if (i < j) swap(a[i], a[j]); } //バタフライ演算 for(int i = 1; i < n; i *= 2) { rep(j,i){ complex<double> w = polar((double)1.0, 2*PI/(i*2)*(rev?-1:1)*j); for(int k = 0; k < n; k += i * 2) { complex<double> s = a[j+k]; complex<double> t = a[j+k+i]*w; a[j+k] = s+t; a[j+k+i] = s-t; } } } if (rev) rep(i,n) a[i] /= n; return a; } void mul(vector<int>& a, vector<int>& b, vector<int>& c) { int s = (int)a.size() + (int)b.size() - 1,t = 1; while (t < s) t *= 2; vector<complex<double> > A(t), B(t); c.resize(t); rep(i,a.size()) A[i].real(a[i]); rep(i,b.size()) B[i].real(b[i]); A = fft(A),B = fft(B); rep(i,t) A[i] *= B[i]; A = fft(A, true); c.resize(s); //整数に直す rep(i,s) c[i] = round(A[i].real()); } vector<int> c[2*MAX_N]; int cnt[MAX_N]; int main() { int n = in(), B = in(); rep(i,n){ cnt[in()]++; } make(); int id = 0, num = 0; priority_queue<P, vector<P>, greater<P> > que; rrep(i,MAX_N){ if(!cnt[i]) continue; c[num] = {prod(id+cnt[i]-1, cnt[i]) % MOD, (int)((ll)prod(id+cnt[i]-1, cnt[i]-1) * cnt[i] % MOD)}; que.push(P(2, num++)); id += cnt[i]; } while(len(que) >= 2){ int p = que.top().se; que.pop(); int q = que.top().se; que.pop(); mul(c[p], c[q], c[num]); que.push(P(len(c[num]), num)); num++; } int index = que.top().se; int ans = 0, nB = 1; rep(i, len(c[index])){ ans = (ans + (((ll)c[index][i] * i) % MOD) * nB) % MOD; nB = (ll)nB * B % MOD; } cout << ans << "\n"; return 0; }