結果

問題 No.1996 <><
ユーザー srjywrdnprkt
提出日時 2023-05-14 01:23:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,091 ms / 2,000 ms
コード長 1,753 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 117,656 KB
最終ジャッジ日時 2025-02-13 00:20:50
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0