結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2019-06-24 20:45:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 946 bytes |
コンパイル時間 | 398 ms |
コンパイル使用メモリ | 55,124 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:43:08 |
合計ジャッジ時間 | 1,078 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <string> using namespace std; int main() { int N, K; string S; cin >> N >> K; cin >> S; int cnt; if (S[K - 1] == '(') { cnt = 1; for (int i = K; i < N; i++) { if (S[i] == '(') { cnt++; } else { cnt--; if (cnt == 0) { cout << i + 1 << endl; return 0; } } } } else { cnt = -1; for (int i = K - 2; i >= 0; i--) { if (S[i] == '(') { cnt++; if (cnt == 0) { cout << i + 1 << endl; return 0; } } else { cnt--; } } } return 0; }