結果

問題 No.1996 <><
ユーザー trineutron
提出日時 2022-07-01 22:10:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,263 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 209,588 KB
最終ジャッジ日時 2025-01-30 02:54:36
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/fenwicktree>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint1000000007;

void compress(vector<int> &a) {
    auto sorted{a};
    sort(sorted.begin(), sorted.end());
    sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());
    for (auto &&x : a) {
        x = lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin();
    }
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    compress(a);
    string s;
    cin >> s;

    vector dp(n + 1, vector<mint>(k + 1));
    vector t(k + 1, fenwick_tree<mint>(n));
    for (int i = 0; i < n; i++) {
        dp.at(i + 1).at(0) = 1;
        t.at(0).add(a.at(i), 1);
        for (int j = 0; j <= k; j++) {
            dp.at(i + 1).at(j) += dp.at(i).at(j);
            if (j == k) continue;
            mint d;
            if (s.at(j) == '<') {
                d = t.at(j).sum(0, a.at(i));
            } else {
                d = t.at(j).sum(a.at(i) + 1, n);
            }
            dp.at(i + 1).at(j + 1) += d;
            t.at(j + 1).add(a.at(i), d);
        }
    }

    cout << dp.back().back().val() << endl;
    return 0;
}
0