結果

問題 No.1996 <><
ユーザー tnakao0123tnakao0123
提出日時 2022-07-03 02:11:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 55,852 KB
実行使用メモリ 11,896 KB
最終ジャッジ日時 2023-08-18 19:26:11
合計ジャッジ時間 4,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 72 ms
7,440 KB
testcase_12 AC 190 ms
11,896 KB
testcase_13 AC 169 ms
11,840 KB
testcase_14 AC 191 ms
11,548 KB
testcase_15 AC 173 ms
10,256 KB
testcase_16 AC 107 ms
9,404 KB
testcase_17 AC 166 ms
10,336 KB
testcase_18 AC 61 ms
7,320 KB
testcase_19 AC 86 ms
8,104 KB
testcase_20 AC 76 ms
7,900 KB
testcase_21 AC 120 ms
9,436 KB
testcase_22 AC 186 ms
10,612 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 60 ms
7,380 KB
testcase_25 AC 26 ms
5,220 KB
testcase_26 AC 47 ms
6,552 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 24 ms
5,060 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 9 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1996.cc:  No.1996 <>< - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1500;
const int MOD = 1000000007;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }
};

typedef MI<MOD> mi;

template <typename T>
struct BIT {
  int n;
  vector<T> bits;
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    bits.assign(n + 1, 0);
  }

  T sum(int x) {
    x = min(x, n);
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    if (x <= 0) return;
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  int lower_bound(T v) {
    int	k = 1;
    while ((k << 1) <= n) k <<=	1;
    int	x = 0;
    for	(; k > 0; k >>= 1)
      if (x + k <= n && bits[x + k] < v) {
        x += k;
        v -= bits[x];
      }
    return x + 1;
  }
};

/* global variables */

int as[MAX_N], uas[MAX_N];
char s[MAX_N + 4];
BIT<mi> bits[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  scanf("%s", s);

  copy(as, as + n, uas);
  sort(uas, uas + n);
  int m = unique(uas, uas + n) - uas;

  for (int i = 0; i <= k; i++) bits[i].init(m);

  for (int i = 0; i < n; i++) {
    int ai = lower_bound(uas, uas + m, as[i]) - uas;
    for (int j = k - 1; j >= 0; j--) {
      mi dj =
	(s[j] == '<') ? bits[j].sum(ai) : bits[j].sum(m) - bits[j].sum(ai + 1);
      if (dj.v != 0)
	bits[j + 1].add(ai + 1, dj);
    }

    bits[0].add(ai + 1, 1);
  }

  printf("%d\n", bits[k].sum(m).v);
  return 0;
}
0