結果

問題 No.1996 <><
ユーザー lloyzlloyz
提出日時 2022-07-02 17:50:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 977 ms / 2,000 ms
コード長 1,629 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 97,696 KB
最終ジャッジ日時 2023-08-18 09:10:41
合計ジャッジ時間 15,582 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
70,984 KB
testcase_01 AC 75 ms
71,196 KB
testcase_02 AC 74 ms
71,136 KB
testcase_03 AC 81 ms
75,564 KB
testcase_04 AC 72 ms
71,100 KB
testcase_05 AC 74 ms
71,372 KB
testcase_06 AC 73 ms
70,984 KB
testcase_07 AC 73 ms
71,056 KB
testcase_08 AC 99 ms
77,276 KB
testcase_09 AC 77 ms
75,844 KB
testcase_10 AC 94 ms
77,172 KB
testcase_11 AC 637 ms
87,600 KB
testcase_12 AC 948 ms
97,568 KB
testcase_13 AC 977 ms
97,696 KB
testcase_14 AC 965 ms
97,348 KB
testcase_15 AC 849 ms
94,216 KB
testcase_16 AC 755 ms
91,848 KB
testcase_17 AC 856 ms
93,992 KB
testcase_18 AC 552 ms
87,104 KB
testcase_19 AC 643 ms
89,600 KB
testcase_20 AC 614 ms
88,416 KB
testcase_21 AC 773 ms
91,884 KB
testcase_22 AC 880 ms
94,876 KB
testcase_23 AC 139 ms
78,124 KB
testcase_24 AC 548 ms
87,184 KB
testcase_25 AC 325 ms
82,772 KB
testcase_26 AC 475 ms
85,140 KB
testcase_27 AC 189 ms
79,252 KB
testcase_28 AC 91 ms
76,348 KB
testcase_29 AC 312 ms
82,100 KB
testcase_30 AC 112 ms
77,908 KB
testcase_31 AC 194 ms
79,480 KB
testcase_32 AC 100 ms
77,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    def add(self, p, x):
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            self.data[p - 1] %= self.mod
            p += p & -p

    def sum(self, l, r):
        '''範囲[l, r)(lからr-1まで)の総和を求める'''
        return (self._sum(r) - self._sum(l)) % self.mod

    def _sum(self, r):
        '''範囲[0, r)(0からr-1まで)の総和を求める'''
        s = 0
        while r > 0:
            s += self.data[r - 1]
            s %= self.mod
            r -= r & -r
        return s

from bisect import bisect_left
def compression(lst):
    sort_lst = sorted(set(lst))
    compression_lst = [None for _ in range(len(lst))]
    ele2ind_dict = dict()
    for i, ele in enumerate(lst):
        compression_lst[i] = bisect_left(sort_lst, ele)
        ele2ind_dict[ele] = compression_lst[i]
    return sort_lst, compression_lst, ele2ind_dict

n, k = map(int, input().split())
A = list(map(int, input().split()))
S = list(input())
mod = 10**9 + 7

sortedsetA, compA, _ = compression(A)
compB = [len(sortedsetA) - ai - 1 for ai in compA]
DP = [[0 for _ in range(n)] for _ in range(k + 1)]
for i in range(n):
    DP[0][i] = 1
for i in range(k):
    s = S[i]
    FT = Fenwick_Tree(n, mod)
    if s == '<':
        L = compA
    else:
        L = compB
    for j in range(n):
        ele = L[j]
        FT.add(ele, DP[i][j])
        if ele > 0:
            DP[i + 1][j] = FT._sum(ele)

ans = 0
for i in range(n):
    ans += DP[k][i]
    ans %= mod
print(ans)
0