結果

問題 No.22 括弧の対応
ユーザー mkawa2
提出日時 2019-12-16 23:11:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 724 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-20 07:46:21
合計ジャッジ時間 1,588 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n, k = MI()
    s = input()
    L = n // 2
    serial = []
    hp = []
    for c in s:
        if c == "(":
            serial.append(L)
            heappush(hp, L)
            L -= 1
        else:
            R = heappop(hp)
            serial.append(-R)
    target = serial[k - 1]
    print(serial.index(-target) + 1)
            
main()
0