結果

問題 No.22 括弧の対応
コンテスト
ユーザー liny_tail
提出日時 2020-08-12 09:53:35
言語 Python3
(3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 23 ms / 5,000 ms
+ 741µs
コード長 348 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 54 ms
コンパイル使用メモリ 14,592 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2026-11-10 21:37:20
合計ジャッジ時間 2,309 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, K = [int(i) for i in input().strip().split(' ')]
S = [[i, n] for n, i in enumerate(list(input().strip()))]

p = 0
while True:
  if S[p][0] + S[p + 1][0] == '()':
    if K - 1 in [S[p][1], S[p + 1][1]]:
      print([S[p + 1][1], S[p][1]][[S[p][1], S[p + 1][1]].index(K - 1)] + 1)
      exit(0)
    
    del S[p:p+2]
    p -= 1
  else:
    p += 1
0