結果

問題 No.22 括弧の対応
ユーザー togatogatogatoga
提出日時 2015-08-16 08:45:19
言語 Python2
(2.7.18)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 342 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 6,380 KB
最終ジャッジ日時 2023-09-27 12:56:19
合計ジャッジ時間 1,323 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,860 KB
testcase_01 AC 11 ms
5,864 KB
testcase_02 AC 11 ms
5,924 KB
testcase_03 AC 13 ms
6,188 KB
testcase_04 AC 12 ms
6,072 KB
testcase_05 AC 12 ms
5,996 KB
testcase_06 AC 12 ms
6,184 KB
testcase_07 AC 12 ms
6,132 KB
testcase_08 AC 12 ms
6,056 KB
testcase_09 AC 13 ms
6,096 KB
testcase_10 AC 11 ms
6,032 KB
testcase_11 AC 12 ms
6,164 KB
testcase_12 AC 12 ms
6,116 KB
testcase_13 AC 14 ms
6,156 KB
testcase_14 AC 11 ms
5,968 KB
testcase_15 AC 13 ms
6,332 KB
testcase_16 AC 13 ms
6,380 KB
testcase_17 AC 11 ms
5,888 KB
testcase_18 AC 11 ms
5,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
N,K = map(int, raw_input().split())
pare = raw_input()
stack = []
for i in range(N):
    if (pare[i] == '('):
        stack.append(["(", i + 1])
    else:
        pos = stack.pop()
        if ((i + 1) == K):
            print pos[1]
            sys.exit(0)
        if (pos[1] == K):
            print i + 1
            sys.exit(0)
0