結果

問題 No.22 括弧の対応
ユーザー MiyamonYMiyamonY
提出日時 2019-09-05 00:12:45
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 515 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 14,148 KB
最終ジャッジ日時 2023-09-27 13:41:09
合計ジャッジ時間 1,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
11,924 KB
testcase_01 AC 17 ms
12,068 KB
testcase_02 AC 15 ms
11,864 KB
testcase_03 AC 17 ms
12,164 KB
testcase_04 AC 17 ms
12,000 KB
testcase_05 AC 16 ms
12,144 KB
testcase_06 AC 16 ms
12,228 KB
testcase_07 AC 16 ms
12,244 KB
testcase_08 AC 16 ms
11,996 KB
testcase_09 AC 16 ms
12,184 KB
testcase_10 AC 16 ms
12,056 KB
testcase_11 AC 14 ms
12,016 KB
testcase_12 AC 17 ms
12,072 KB
testcase_13 AC 18 ms
14,148 KB
testcase_14 AC 16 ms
12,124 KB
testcase_15 AC 16 ms
12,268 KB
testcase_16 AC 16 ms
12,152 KB
testcase_17 AC 15 ms
11,924 KB
testcase_18 AC 17 ms
14,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(use data.queue)

(let* ((pair (map string->number (string-split (read-line) #\space)))
       (k (cadr pair))
       (s (read-line)))

  (print
   (let loop ((chars (string->list s))
	      (i 1)
	      (stack (make-queue)))
     (cond
      ((eqv? (car chars) #\()
       (queue-push! stack i)
       (loop (cdr chars) (+ i 1) stack))
      ((eqv? (car chars) #\))
       (let1 popped (queue-pop! stack)
	     (cond ((= popped k) i)
		   ((= i k) popped)
		   (else
		    (loop (cdr chars) (+ i 1) stack)))))))))
0