結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2020-02-07 00:25:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 536 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 71,552 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:47:18 |
合計ジャッジ時間 | 1,267 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <stack> using namespace std; int main(void) { int n, k; string s; cin >> n >> k >> s; --k; stack<int> st; int cnt = 0, ans = 0; for (int i = 0; i < n; ++i) { if (s[i] == '(') { if (i == k) st.push(1); else st.push(0); } else { if (st.top() == 1) ans = i + 1; st.pop(); } } for (int i = n - 1; i >= 0; --i) { if (s[i] == ')') { if (i == k) st.push(1); else st.push(0); } else { if (st.top() == 1) ans = i + 1; st.pop(); } } cout << ans << endl; return 0; }