結果

問題 No.22 括弧の対応
ユーザー jamadjamad
提出日時 2017-06-16 03:07:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 399 ms / 5,000 ms
コード長 454 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 9,108 KB
最終ジャッジ日時 2023-09-27 13:16:37
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,796 KB
testcase_01 AC 15 ms
7,848 KB
testcase_02 AC 17 ms
7,784 KB
testcase_03 AC 399 ms
9,108 KB
testcase_04 AC 98 ms
8,612 KB
testcase_05 AC 83 ms
8,600 KB
testcase_06 AC 180 ms
8,800 KB
testcase_07 AC 255 ms
8,892 KB
testcase_08 AC 138 ms
8,848 KB
testcase_09 AC 113 ms
8,644 KB
testcase_10 AC 230 ms
8,864 KB
testcase_11 AC 78 ms
8,536 KB
testcase_12 AC 141 ms
8,900 KB
testcase_13 AC 245 ms
9,036 KB
testcase_14 AC 22 ms
8,252 KB
testcase_15 AC 335 ms
8,936 KB
testcase_16 AC 339 ms
8,940 KB
testcase_17 AC 15 ms
7,740 KB
testcase_18 AC 16 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
S=input()
I=[x+1 for x in range(N)]
ANS={}
while 1:
    before=len(S)
#    print(I)
#    print(S)
#    print('########')
    
    idx=S.find('()')
#    S.replace('()','')
    T=list(S)
    if not T:break
    T.pop(idx)
    if not T:break
    T.pop(idx)
#    print(T)
    S=''.join(T)
    
    a=I.pop(idx)
    b=I.pop(idx)
    ANS[a]=b
    ANS[b]=a
    if before==len(S):
        break
#print(ANS)
#print(N,K,S)
print(ANS[K])
0