結果
問題 | No.22 括弧の対応 |
ユーザー | Tomoyarn |
提出日時 | 2022-02-19 11:43:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 41 ms / 5,000 ms |
コード長 | 482 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,212 KB |
実行使用メモリ | 60,536 KB |
最終ジャッジ日時 | 2024-06-29 10:22:04 |
合計ジャッジ時間 | 1,889 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#yukicoder No.22 括弧の対応 N, K = map(int, input().split()) S = input() d = [] cnt = 0 for i in range(N): if S[i] == "(": cnt += 1 else: cnt -= 1 d.append(cnt) i = K - 1 if S[i] == ")": while True: i -= 1 if d[i] == d[K - 1] + 1 and S[i] == "(": print(i + 1) break else: while True: i += 1 if d[i] == d[K - 1] - 1 and S[i] == ")": print(i + 1) break