結果

問題 No.829 成長関数インフレ中
ユーザー kyort0nkyort0n
提出日時 2019-05-03 23:51:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,723 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 180,656 KB
実行使用メモリ 19,992 KB
最終ジャッジ日時 2023-08-30 07:03:03
合計ジャッジ時間 3,675 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 22 ms
4,864 KB
testcase_13 WA -
testcase_14 AC 16 ms
6,104 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, B;
    cin >> N >> B;
    map<ll, ll> mp;
    vector<ll> S(N);
    for(int i = 0; i < N; i++) {
        cin >> S[i];
        mp[S[i]]++;
    }
    sort(S.begin(), S.end(), greater<ll>());
    S.erase(unique(S.begin(), S.end()), S.end());
    ll SIZE = S.size();
    vector<l_l> f(S.size() + 1);
    ll now = 0;
    for(ll i = 0; i < SIZE; i++) {
        ll NEXT = now + mp[S[i]];
        f[i+1].first = 1;
        for(ll j = now; j < NEXT; j++) {
            f[i+1].first *= j;
            f[i+1].first %= mod;
        }
        f[i+1].second = 1;
        for(ll j = now + 1; j <= NEXT; j++) {
            f[i+1].second *= j;
            f[i+1].second %= mod;
        }
        f[i+1].second -= f[i+1].first;
        f[i+1].second %= mod;
        now = NEXT;
        swap(f[i+1].first, f[i+1].second);
        //cerr << f[i+1].first << " " << f[i+1].second << endl;
    }
    ll sum[200500];
    ll sumafter[200500];
    sum[0] = 1;
    for(ll i = 1; i <= SIZE; i++) {
        sum[i] = sum[i-1] * ((f[i].first * B + f[i].second) % mod);
        sum[i] %= mod;
    }
    sumafter[SIZE+1] = 1;
    for(ll i = SIZE; i >= 1; i--) {
        sumafter[i] = sumafter[i+1] * ((f[i].first * B + f[i].second) % mod) % mod;
    }
    ll ans = 0;
    for(ll i = 1; i <= SIZE; i++) {
        ans += (sum[i-1] * sumafter[i+1] % mod) * f[i].first % mod;
    }
    ans *= B;
    ans %= mod;
    cout << ans << endl;
    return 0;
}
0