結果

問題 No.22 括弧の対応
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2018-05-28 17:06:22
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 421 bytes
コンパイル時間 3,955 ms
コンパイル使用メモリ 68,868 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-12 20:06:52
合計ジャッジ時間 4,664 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 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
  h = 0
  L, R: seq[int] = @[]

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

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