結果

問題 No.22 括弧の対応
ユーザー Theta
提出日時 2022-10-21 18:49:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 429 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-01 04:22:01
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N, K = map(int, input().split())
    S = input()

    stack = []
    for idx, bracket in enumerate(S, 1):
        match bracket:
            case "(":
                stack.append(idx)
            case ")":
                another = stack.pop()
                if idx == K:
                    print(another)
                if another == K:
                    print(idx)


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