結果

問題 No.1996 <><
ユーザー SSRSSSRS
提出日時 2022-07-01 21:33:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 176,944 KB
実行使用メモリ 20,708 KB
最終ジャッジ日時 2023-08-17 08:52:34
合計ジャッジ時間 3,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 26 ms
11,752 KB
testcase_12 AC 50 ms
20,708 KB
testcase_13 AC 71 ms
20,660 KB
testcase_14 AC 67 ms
20,224 KB
testcase_15 AC 58 ms
17,864 KB
testcase_16 AC 50 ms
16,044 KB
testcase_17 AC 59 ms
17,840 KB
testcase_18 AC 33 ms
11,756 KB
testcase_19 AC 41 ms
13,252 KB
testcase_20 AC 40 ms
12,560 KB
testcase_21 AC 50 ms
15,976 KB
testcase_22 AC 59 ms
18,008 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 33 ms
11,760 KB
testcase_25 AC 16 ms
7,264 KB
testcase_26 AC 28 ms
10,164 KB
testcase_27 AC 7 ms
4,552 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 15 ms
7,024 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 6 ms
4,604 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
template <typename T>
struct binary_indexed_tree{
  int N;
  vector<T> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  void add(int i, T x){
    i++;
    while (i <= N){
      BIT[i] += x;
      i += i & -i;
    }
  }
  T sum(int i){
    T ans = 0;
    while (i > 0){
      ans += BIT[i];
      i -= i & -i;
    }
    return ans;
  }
  T sum(int L, int R){
    return sum(R) - sum(L);
  }
};
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<char> s(K);
  for (int i = 0; i < K; i++){
    cin >> s[i];
  }
  vector<int> B = A;
  sort(B.begin(), B.end());
  B.erase(unique(B.begin(), B.end()), B.end());
  for (int i = 0; i < N; i++){
    A[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
  }
  int cnt = B.size();
  vector<vector<long long>> dp(K + 1, vector<long long>(N, 0));
  for (int i = 0; i < N; i++){
    dp[0][i] = 1;
  }
  for (int i = 0; i < K; i++){
    binary_indexed_tree<long long> BIT(cnt);
    for (int j = 0; j < N; j++){
      if (s[i] == '<'){
        dp[i + 1][j] = BIT.sum(0, A[j]) % MOD;
      }
      if (s[i] == '>'){
        dp[i + 1][j] = BIT.sum(A[j] + 1, cnt) % MOD;
      }
      BIT.add(A[j], dp[i][j]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans += dp[K][i];
  }
  ans %= MOD;
  cout << ans << endl;
}
0