結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-08-03 16:31:39 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 34 ms / 5,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-20 07:03:11 |
合計ジャッジ時間 | 1,461 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
N, K = map(int, input().split())S = input()lcount = 0rcount = 0judge = 0if S[K-1] == '(':for i in range(K):if S[i] == '(':lcount += 1else:lcount -= 1judge = lcount - 1i += 1while lcount != judge :if i >= N:breakif S[i] == ')':lcount -= 1else:lcount += 1i += 1print(i)else:for i in range(N-1, K-2, -1):if S[i] == ')':rcount += 1else:rcount -= 1judge = rcount - 1i -= 1while rcount != judge :if i < 0 :breakif S[i] == '(':rcount -= 1else:rcount += 1i -= 1print(i+2)