結果

問題 No.1996 <><
ユーザー rlangevinrlangevin
提出日時 2023-11-13 00:02:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,049 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 83,712 KB
最終ジャッジ日時 2023-11-13 00:03:07
合計ジャッジ時間 13,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,736 KB
testcase_01 AC 42 ms
55,736 KB
testcase_02 AC 42 ms
55,736 KB
testcase_03 AC 51 ms
63,548 KB
testcase_04 AC 41 ms
55,736 KB
testcase_05 AC 41 ms
55,736 KB
testcase_06 AC 41 ms
55,736 KB
testcase_07 AC 41 ms
55,736 KB
testcase_08 AC 74 ms
75,864 KB
testcase_09 AC 51 ms
63,552 KB
testcase_10 AC 67 ms
72,656 KB
testcase_11 AC 545 ms
80,492 KB
testcase_12 AC 1,049 ms
83,712 KB
testcase_13 AC 899 ms
82,324 KB
testcase_14 AC 804 ms
82,564 KB
testcase_15 AC 754 ms
81,396 KB
testcase_16 AC 657 ms
81,064 KB
testcase_17 AC 735 ms
81,276 KB
testcase_18 AC 483 ms
79,336 KB
testcase_19 AC 533 ms
79,736 KB
testcase_20 AC 518 ms
79,720 KB
testcase_21 AC 682 ms
80,504 KB
testcase_22 AC 776 ms
81,540 KB
testcase_23 AC 111 ms
76,260 KB
testcase_24 AC 479 ms
79,080 KB
testcase_25 AC 271 ms
77,256 KB
testcase_26 AC 424 ms
78,560 KB
testcase_27 AC 147 ms
76,404 KB
testcase_28 AC 59 ms
68,396 KB
testcase_29 AC 263 ms
77,248 KB
testcase_30 AC 88 ms
76,128 KB
testcase_31 AC 158 ms
76,492 KB
testcase_32 AC 75 ms
76,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *
from copy import deepcopy
def compress(lst):
    """
    B: lstを座圧したリスト
    D: indexから元の値を取得する辞書
    """
    B = []
    D = dict()
    vals = deepcopy(lst)
    vals = list(set(vals))
    vals.sort()
    for i in range(len(lst)):
        ind = bisect_left(vals, lst[i])
        B.append(ind)
    for i in range(len(B)):
        D[lst[i]] = B[i]
    return B, D, vals


class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get_size(self, x):
        x = self.find(x)
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get(self, k):
        k += 1
        x, r = 0, 1
        while r < self._n:
            r <<= 1
        len = r
        while len:
            if x + len - 1 < self._n:
                if self.data[x + len - 1] < k:
                    k -= self.data[x + len - 1]
                    x += len
            len >>= 1
        return x


N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9 + 7
A, _, _ = compress(A) 
S = list(input())
pre = [0] * (N + 1)
for i in range(N + 1):
    pre[i] = 1
    
for i in range(K):
    T = Fenwick_Tree(N)
    dp = [0] * (N + 1)
    for j in range(N):
        if S[i] == "<":
            dp[j] = T.sum(0, A[j])
        else:
            dp[j] = T.sum(A[j] + 1, N)
        dp[j] %= mod
        T.add(A[j], pre[j])
    dp, pre = pre, dp
    
print(sum(pre)%mod)
0