結果

問題 No.829 成長関数インフレ中
コンテスト
ユーザー WutongDeath
提出日時 2026-03-23 23:49:52
言語 C++14
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,194 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 326 ms
コンパイル使用メモリ 84,480 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2026-08-04 03:17:25
合計ジャッジ時間 4,646 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
}
0