結果

問題 No.1996 <><
ユーザー Kiri8128Kiri8128
提出日時 2022-07-01 22:43:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,616 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 95,912 KB
最終ジャッジ日時 2024-05-04 17:06:33
合計ジャッジ時間 20,182 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 40 ms
52,224 KB
testcase_02 AC 41 ms
52,224 KB
testcase_03 AC 49 ms
60,416 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 AC 40 ms
52,352 KB
testcase_06 AC 40 ms
52,224 KB
testcase_07 AC 40 ms
52,608 KB
testcase_08 AC 74 ms
76,032 KB
testcase_09 AC 50 ms
61,184 KB
testcase_10 AC 67 ms
71,168 KB
testcase_11 AC 781 ms
86,320 KB
testcase_12 AC 1,509 ms
95,300 KB
testcase_13 AC 1,616 ms
95,912 KB
testcase_14 AC 1,521 ms
94,724 KB
testcase_15 AC 1,488 ms
92,264 KB
testcase_16 AC 1,289 ms
90,424 KB
testcase_17 AC 1,481 ms
92,712 KB
testcase_18 AC 873 ms
85,932 KB
testcase_19 AC 1,033 ms
87,564 KB
testcase_20 AC 876 ms
86,936 KB
testcase_21 AC 1,165 ms
90,176 KB
testcase_22 AC 1,376 ms
92,672 KB
testcase_23 AC 126 ms
76,872 KB
testcase_24 AC 787 ms
85,632 KB
testcase_25 AC 395 ms
81,536 KB
testcase_26 AC 663 ms
84,584 KB
testcase_27 AC 188 ms
78,576 KB
testcase_28 AC 64 ms
65,920 KB
testcase_29 AC 370 ms
81,236 KB
testcase_30 AC 105 ms
76,520 KB
testcase_31 AC 182 ms
78,040 KB
testcase_32 AC 91 ms
76,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class DualBIT():
    def __init__(self, init):
        if type(init) == int:
            self.n = init + 1
            self.X = [0] * self.n
        else:
            self.n = len(init) + 1
            self.X = [0] + init
            for i in range(1, self.n):
                if i + (i & -i) < self.n:
                    self.X[i + (i & -i)] += self.X[i]
    def _add(self, i, x=1):
        i += 1
        while i < self.n:
            self.X[i] = (self.X[i] + x) % P
            i += i & (-i)

    def add_range(self, l, r, x=1):
        self._add(l, x)
        self._add(r, -x)
    
    def getvalue(self, i):
        ret = 0
        i += 1
        while i != 0:
            ret = (ret + self.X[i]) % P
            i -= i & (-i)
        return ret
    
    def disp(self):
        return [self.getvalue(i) for i in range(N)]

P = 10 ** 9 + 7
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
S = [1 if s == "<" else -1 for s in input()]
SA = sorted(set(A))
IA = {a: i for i, a in enumerate(SA)}
AA = [IA[a] for a in A]
M = len(SA)
bits = [DualBIT(N) for _ in range(K + 1)]
bits[0].add_range(0, M, 1)
ans = 0
for i in range(N):
    a = AA[i]
    for j in range(1, K + 1)[::-1]:
        c = bits[j].getvalue(a)
        if j == K:
            ans += c
            continue
        s = S[j]
        if s > 0:
            bits[j+1].add_range(a + 1, M, c)
        else:
            bits[j+1].add_range(0, a, c)
    
    s = S[0]
    if s > 0:
        bits[1].add_range(a + 1, M, 1)
    else:
        bits[1].add_range(0, a, 1)
print(ans % P)
0