結果

問題 No.22 括弧の対応
ユーザー tsuchinagatsuchinaga
提出日時 2019-02-27 09:28:24
言語 Go
(1.22.1)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 486 bytes
コンパイル時間 11,073 ms
コンパイル使用メモリ 200,588 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 13:35:26
合計ジャッジ時間 11,993 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var n, k int
	s := ""
	_, _ = fmt.Scan(&n, &k, &s)

	b := make([]int, 0)          // 開き括弧の位置
	sets := make(map[int]int, 0) // 開始位置: 終了位置のマップ
	for i, c := range s {
		if string(c) == "(" {
			b = append(b, i)
		} else {
			if b[len(b)-1] == k-1 {
				fmt.Println(i + 1)
				break
			} else if i == k-1 {
				fmt.Println(b[len(b)-1] + 1)
				break
			}
			sets[b[len(b)-1]] = i
			b = b[:len(b)-1]
		}
	}
}
0