結果
| 問題 | No.829 成長関数インフレ中 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-23 23:49:52 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,194 bytes |
| 記録 | |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 84,448 KB |
| 実行使用メモリ | 18,468 KB |
| 最終ジャッジ日時 | 2026-03-23 23:50:30 |
| 合計ジャッジ時間 | 31,958 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 TLE * 10 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int N = 200010, MOD = 1000000007;
int n, b, ans, a[N];
bool st[N];
int QMI(int a, int k) {
int ret = 1 % MOD;
while (k) {
if (k & 1) {
ret = 1LL * ret * a % MOD;
}
a = 1LL * a * a % MOD;
k >>= 1;
}
return ret;
}
void DFS(int rem, int ma, int cnt, int pre) {
if (rem == 0) {
// cout << "rem: " << rem << " ma: " << ma << " cnt: " << cnt << " pre: " << pre << " " << 1LL * cnt * QMI(b, cnt) % MOD << endl;
ans = (0LL + ans + 1LL * cnt * QMI(b, cnt) % MOD) % MOD;
return;
}
for (int i = 1; i <= n; ++i) {
if (!st[i]) {
st[i] = true;
if (a[i] > pre) ++cnt;
DFS(rem - 1, max(ma, a[i]), cnt, max(pre, a[i]));
if (a[i] > pre) --cnt;
st[i] = false;
}
}
}
int main() {
// freopen("growth.in", "r", stdin);
// freopen("growth.out", "w", stdout);
scanf("%d%d", &n, &b);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
DFS(n, 0, 0, -1);
printf("%d\n", ans);
return 0;
}