結果

問題 No.1996 <><
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-14 01:23:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 831 ms / 2,000 ms
コード長 1,753 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 120,156 KB
実行使用メモリ 20,800 KB
最終ジャッジ日時 2023-08-19 20:32:15
合計ジャッジ時間 10,964 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 311 ms
12,068 KB
testcase_12 AC 831 ms
20,744 KB
testcase_13 AC 831 ms
20,800 KB
testcase_14 AC 789 ms
20,296 KB
testcase_15 AC 709 ms
17,924 KB
testcase_16 AC 551 ms
16,076 KB
testcase_17 AC 689 ms
17,804 KB
testcase_18 AC 267 ms
11,744 KB
testcase_19 AC 368 ms
13,324 KB
testcase_20 AC 395 ms
12,908 KB
testcase_21 AC 543 ms
16,220 KB
testcase_22 AC 647 ms
18,384 KB
testcase_23 AC 16 ms
4,380 KB
testcase_24 AC 269 ms
11,776 KB
testcase_25 AC 116 ms
7,744 KB
testcase_26 AC 220 ms
9,928 KB
testcase_27 AC 37 ms
4,704 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 107 ms
7,068 KB
testcase_30 AC 5 ms
4,380 KB
testcase_31 AC 39 ms
4,616 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

template<class T> struct BIT {
    vector<T> bit;
    long long N;
    T P;

    BIT (long long n, T p = 0){
        N = n;
        P = p;
        bit.resize(N);
    }

    void add(long long loc, T val){
        loc++;
        while(loc <= N){
            bit[loc-1] += val;
            if (P) bit[loc-1] %= P;
            loc += loc & -loc;
        }
    }

    long long sum(long long l, long long r){
        T res = _sum(r) - _sum(l-1);
        if (P) res = (res + P) % P;
        return res;
    }

    long long _sum(long long r){
        r++;
        T res = 0;
        while(r > 0){
            res += bit[r-1];
            if (P) res %= P;
            r -= r & -r;
        }
        return res;
    }
};

template <typename T>
void compress(vector<T> &A){

    map<T, T> comp;
    int N = A.size(), i=0;
    for (int i=0; i<N; i++) comp[A[i]];

    for (auto &e : comp){
        e.second = i;
        i++;
    }

    for (int i=0; i<N; i++) A[i] = comp[A[i]];
}
const ll modc = 1e9+7;

int main(){

    ll N, K;
    string S;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    cin >> S;
    compress(A);
    vector<BIT<ll>> dp(K+1, BIT<ll>(N, modc));

    for (int i=0; i<N; i++){
        for (int j=1; j<=K; j++){
            if (S[j-1] == '<') dp[j].add(A[i], dp[j-1].sum(0, A[i]-1));
            else dp[j].add(A[i], dp[j-1].sum(A[i]+1, N-1));
        }
        dp[0].add(A[i], 1);
    }

    cout << dp[K].sum(0, N-1) << endl;

    return 0;
}
0