結果

問題 No.22 括弧の対応
コンテスト
ユーザー ID 21712
提出日時 2025-01-24 02:09:22
言語 Go
(1.27.3 + ACL)
コンパイル:
/usr/bin/go_c
実行:
./Main
結果
AC  
実行時間 12 ms / 5,000 ms
+ 664µs
コード長 302 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 12,097 ms
コンパイル使用メモリ 275,536 KB
実行使用メモリ 9,844 KB
最終ジャッジ日時 2026-11-11 04:18:19
合計ジャッジ時間 12,840 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package main

import . "fmt"

func main() {
	var n,k int
	var s string
	Scan(&n,&k,&s)
	p := make([]int, n)
	t := make([]int, 0, n)
	for i,r := range s {
		switch r {
			case '(':
				t=append(t,i)
			case ')':
				x := len(t)
				j:=t[x-1]
				t=t[:x-1]
				p[i],p[j]=j+1,i+1
		}
	}
	Println(p[k-1])
}
0