結果

問題 No.1996 <><
ユーザー ygd.ygd.
提出日時 2022-07-01 23:14:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,710 ms / 2,000 ms
コード長 2,855 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 126,708 KB
最終ジャッジ日時 2023-08-17 10:57:38
合計ジャッジ時間 22,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,092 KB
testcase_01 AC 77 ms
71,216 KB
testcase_02 AC 77 ms
71,352 KB
testcase_03 AC 91 ms
76,084 KB
testcase_04 AC 76 ms
71,436 KB
testcase_05 AC 74 ms
71,436 KB
testcase_06 AC 75 ms
71,456 KB
testcase_07 AC 78 ms
71,160 KB
testcase_08 AC 134 ms
77,804 KB
testcase_09 AC 90 ms
76,120 KB
testcase_10 AC 120 ms
77,260 KB
testcase_11 AC 805 ms
102,212 KB
testcase_12 AC 1,518 ms
126,340 KB
testcase_13 AC 1,710 ms
126,708 KB
testcase_14 AC 1,629 ms
125,196 KB
testcase_15 AC 1,512 ms
120,160 KB
testcase_16 AC 1,330 ms
115,328 KB
testcase_17 AC 1,428 ms
121,152 KB
testcase_18 AC 892 ms
105,700 KB
testcase_19 AC 1,041 ms
107,812 KB
testcase_20 AC 993 ms
105,428 KB
testcase_21 AC 1,322 ms
117,064 KB
testcase_22 AC 1,530 ms
119,816 KB
testcase_23 AC 173 ms
80,312 KB
testcase_24 AC 897 ms
108,076 KB
testcase_25 AC 491 ms
88,812 KB
testcase_26 AC 777 ms
101,320 KB
testcase_27 AC 243 ms
82,916 KB
testcase_28 AC 104 ms
77,304 KB
testcase_29 AC 479 ms
86,944 KB
testcase_30 AC 146 ms
78,964 KB
testcase_31 AC 261 ms
84,048 KB
testcase_32 AC 132 ms
78,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

#和のセグ木にするときは以下の関数を定義する必要あり。
def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def compress(S):
    S = set(S); S = list(S)
    S.sort()
    dic_comp_ori = {}
    dic_ori_comp = {}
    for i,a in enumerate(S):
        dic_ori_comp[a] = i
        dic_comp_ori[i] = a
    return dic_comp_ori, dic_ori_comp 

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    dic_comp_ori, dic_ori_comp = compress(A)
    A = [dic_ori_comp[a] for a in A]
    MAX = len(dic_comp_ori)
    s = str(input())
    # print(A)
    # dp[k][v]: 今k番目の不等号まで完了して、直前の値がvとなる場合の数
    dp = [SegmentTree([0]*MAX,segfunc,0) for _ in range(K+1)]

    for a in A:
        # 初期条件
        dp[0].add(a,1)
        for k in range(K):
            # a未満の和
            if s[k] == '<':
                num = dp[k].sum(0,a)
            # aより大の和
            else:
                num = dp[k].sum(a+1,MAX)
            temp = dp[k+1][a] + num
            temp %= MOD
            dp[k+1].update(a,temp)

    ans = dp[K].sum(0,MAX)
    print(ans%MOD)


if __name__ == '__main__':
    main()
0