結果

問題 No.1996 <><
ユーザー titia
提出日時 2022-07-02 01:33:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 870 ms / 2,000 ms
コード長 1,111 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 82,192 KB
実行使用メモリ 82,596 KB
最終ジャッジ日時 2024-11-26 10:16:24
合計ジャッジ時間 10,892 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=10**9+7

N,K=map(int,input().split())
A=list(map(int,input().split()))

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)))}
A=[compression_dict[a] for a in A] # [2, 3, 0, 1, 4]

LEN=len(A)+5

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        BIT[v]%=mod
        v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        ANS%=mod
        v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
    return ANS


S=input().strip()

DP=[1]*N

for s in S:
    BIT=[0]*(LEN+1)
    NDP=[0]*N

    if s=="<":
        for i in range(N):
            update(A[i],DP[i])

            NDP[i]+=getvalue(A[i]-1)
            NDP[i]%=mod

    else:
        for i in range(N):
            update(A[i],DP[i])

            NDP[i]+=getvalue(LEN)-getvalue(A[i])
            NDP[i]%=mod

    DP=NDP

print(sum(DP)%mod)
0