結果

問題 No.22 括弧の対応
ユーザー むらため
提出日時 2018-12-16 03:23:11
言語 Nim
(2.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 688 bytes
コンパイル時間 3,977 ms
コンパイル使用メモリ 67,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:37:44
合計ジャッジ時間 4,606 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 45) Warning: imported and not used: 'math' [UnusedImport]
/home/judge/data/code/Main.nim(1, 50) Warning: imported and not used: 'sugar' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport]
/home/judge/data/code/Main.nim(1, 35) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,sugar,macros
#import sets,queues,tables,nre,pegs
macro unpack*(rhs: seq,cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `rhs`;())
  for i in 0..<cnt: result[1].add(quote do:`t`[`i`])
template get*():string = stdin.readLine() #.strip()

let
  (N,K) = get().split().map(parseInt).unpack(2)
  S = get()
if S[K-1] == '(':
  var cnt = 1
  for i in K..<N:
    let s = S[i]
    if s == '(': cnt += 1
    else: cnt -= 1
    if cnt == 0:
      echo i+1
      quit()
else:
  var cnt = 1
  for i in countdown(K-2,0):
    let s = S[i]
    if s == ')': cnt += 1
    else: cnt -= 1
    if cnt == 0:
      echo i+1
      quit()
0