結果

問題 No.1996 <><
ユーザー asaringoasaringo
提出日時 2022-07-01 22:23:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 2,848 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 210,088 KB
実行使用メモリ 27,912 KB
最終ジャッジ日時 2023-08-17 09:54:42
合計ジャッジ時間 6,643 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 157 ms
15,596 KB
testcase_12 AC 209 ms
27,908 KB
testcase_13 AC 206 ms
27,912 KB
testcase_14 AC 204 ms
27,908 KB
testcase_15 AC 196 ms
25,868 KB
testcase_16 AC 187 ms
21,844 KB
testcase_17 AC 188 ms
25,760 KB
testcase_18 AC 142 ms
17,496 KB
testcase_19 AC 162 ms
19,612 KB
testcase_20 AC 170 ms
17,656 KB
testcase_21 AC 175 ms
23,652 KB
testcase_22 AC 202 ms
23,776 KB
testcase_23 AC 9 ms
8,336 KB
testcase_24 AC 122 ms
19,400 KB
testcase_25 AC 55 ms
14,916 KB
testcase_26 AC 122 ms
15,416 KB
testcase_27 AC 25 ms
8,604 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 62 ms
12,972 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 24 ms
8,548 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
#define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr);
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

struct Compress{
    vector<int> vec ;
    vector<int> compressForArray(int *A , int n){
        vector<int> B(n) ;
        for(int i = 0 ; i < n ; i++) B[i] = A[i] ;
        vec.resize(n) ;
        sort(A,A+n) ;
        for(int i = 0 ; i < n ; i++){
            auto it = lower_bound(A,A+n,B[i]) ;
            vec[i] = it - A ;
        }
        return vec ;
    }
    vector<int> compressForVector(vector<int> A){
        int n = A.size() ;
        vector<int> B(n) ;
        for(int i = 0 ; i < n ; i++) B[i] = A[i] ;
        vec.resize(n) ;
        sort(A.begin(),A.end()) ;
        for(int i = 0 ; i < n ; i++){
            auto it = lower_bound(A.begin(),A.end(),B[i]) ;
            vec[i] = it - A.begin() ;
        }
        return vec ;
    }
};

const int mod = 1000000007 ;

template<typename T>
struct SegmentTree{
    int n , n_;
    vector<T> dat ;
    SegmentTree(int _n){
        n_ = _n ;
        n = 1 ;
        while(n < _n) n *= 2 ;
        dat.resize(2 * n - 1,0) ;
    }
    void add(int k , T x){
        k += n - 1 ;
        (dat[k] += x) %= mod ;
        while(k > 0){
            k = (k - 1) / 2 ;
            dat[k] = (dat[2*k+1] + dat[2*k+2]) % mod ;
        }
    }
    T sub_query(int a , int b , int k , int l , int r){
        if(r <= a || b <= l) return 0 ;
        if(a <= l && r <= b) return dat[k] ;
        T lef = sub_query(a,b,2*k+1,l,(l+r)/2) ;
        T rig = sub_query(a,b,2*k+2,(l+r)/2,r) ;
        return (lef + rig) % mod ;
    }
    T query(int a , int b){
        return sub_query(a,b,0,0,n) ;
    }
};


int n , k ;
vector<int> A ;
string S ;

ll dp[2020][2020] ;

int main(){
    fast_input_output
    cin >> n >> k ;
    A.resize(n) ;
    rep(i,n) cin >> A[i] ;
    Compress C ;
    vector<int> vec = C.compressForVector(A) ;
    int maxval = 0 ;
    rep(i,vec.size()) chmax(maxval,vec[i]) ;
    maxval++ ;
    cin >> S ;
    int m = k ;
    rep(i,n-m){
        dp[0][i] = 1 ;
    }
    m++ ;
    rrep(i,1,m){
        SegmentTree<ll> segtree(maxval) ;
        rrep(j,i,n){
            segtree.add(vec[j-1],dp[i-1][j-1]) ;
            ll val ;
            if(S[i-1] == '<') val = segtree.query(0,vec[j]) ;
            else val = segtree.query(vec[j]+1,maxval) ;
            dp[i][j] = val ;
        }
    }
    ll res = 0 ;
    rep(i,n) (res += dp[m-1][i]) %= mod ;
    cout << res << endl ;
}
0