結果

問題 No.22 括弧の対応
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2018-05-28 17:09:55
言語 Nim
(2.0.2)
結果
AC  
実行時間 443 ms / 5,000 ms
コード長 374 bytes
コンパイル時間 3,501 ms
コンパイル使用メモリ 68,588 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 13:27:32
合計ジャッジ時間 6,605 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 443 ms
4,376 KB
testcase_04 AC 85 ms
4,380 KB
testcase_05 AC 71 ms
4,376 KB
testcase_06 AC 168 ms
4,380 KB
testcase_07 AC 256 ms
4,380 KB
testcase_08 AC 129 ms
4,376 KB
testcase_09 AC 100 ms
4,376 KB
testcase_10 AC 224 ms
4,376 KB
testcase_11 AC 66 ms
4,376 KB
testcase_12 AC 134 ms
4,380 KB
testcase_13 AC 245 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 343 ms
4,376 KB
testcase_16 AC 349 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils
let
  t = stdin.readLine.split.map(parseInt)
  (n, k) = (t[0], t[1])
var
  s = stdin.readLine
  i = s.high
  L, R: seq[int] = @[]

while s.count('(') > 0:
  i -= 1
  if s[i] == '(':
    s[i] = 'x'
    L.add(i + 1)
    var j = i + 1
    while s[j] != ')': j += 1
    s[j] = 'x'
    R.add(j + 1)

if k in L: echo R[L.find(k)]
else: echo L[R.find(k)]
0