結果
| 問題 |
No.829 成長関数インフレ中
|
| コンテスト | |
| ユーザー |
kyort0n
|
| 提出日時 | 2019-05-03 23:51:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,723 bytes |
| コンパイル時間 | 2,042 ms |
| コンパイル使用メモリ | 183,120 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2024-12-31 20:25:59 |
| 合計ジャッジ時間 | 3,549 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 7 |
ソースコード
#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;
}
kyort0n