結果

問題 No.829 成長関数インフレ中
ユーザー chocoruskchocorusk
提出日時 2019-05-03 23:00:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,663 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 96,248 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-08-30 06:34:47
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,716 KB
testcase_01 AC 3 ms
7,708 KB
testcase_02 AC 2 ms
7,448 KB
testcase_03 AC 2 ms
7,400 KB
testcase_04 AC 3 ms
7,452 KB
testcase_05 AC 2 ms
7,432 KB
testcase_06 AC 2 ms
7,396 KB
testcase_07 AC 3 ms
7,436 KB
testcase_08 AC 3 ms
7,456 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
7,396 KB
testcase_12 AC 60 ms
13,508 KB
testcase_13 AC 6 ms
7,672 KB
testcase_14 AC 42 ms
13,000 KB
testcase_15 AC 27 ms
10,344 KB
testcase_16 AC 49 ms
12,824 KB
testcase_17 AC 86 ms
13,548 KB
testcase_18 AC 68 ms
13,432 KB
testcase_19 AC 60 ms
13,020 KB
testcase_20 AC 76 ms
13,256 KB
testcase_21 AC 37 ms
12,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[1500001], invf[1500001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(x<y) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int n;
ll B;
int c[200010];
ll a[200010], b[200010];
int main()
{
    cin>>n>>B;
    for(int i=0; i<n; i++){
        int s; cin>>s;
        c[s]++;
    }
    int s=0;
    fac(n);
    for(int i=n-1; i>=0; i--){
      if(c[i]==0){
        a[i]=0, b[i]=1;
        continue;
      }
        ll x=f[s+c[i]]*invf[s]%MOD;
        if(s==0) b[i]=0;
        else b[i]=f[s+c[i]-1]*invf[s-1]%MOD;
        a[i]=(x-b[i]+MOD)%MOD;
        s+=c[i];
    }
    ll p=B;
    for(int i=0; i<n; i++){
        p*=((a[i]*B+b[i])%MOD);
        p%=MOD;
    }
    ll q=0;
    for(int i=0; i<n; i++){
        q+=a[i]*inv((a[i]*B+b[i])%MOD);
        q%=MOD;
    }
    cout<<p*q%MOD<<endl;
    return 0;
}
0