結果
問題 | No.22 括弧の対応 |
ユーザー | SSRS |
提出日時 | 2020-08-05 07:58:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 391 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 71,404 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:51:14 |
合計ジャッジ時間 | 1,245 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <string> #include <stack> using namespace std; int main(){ int N, K; cin >> N >> K; K--; string S; cin >> S; int ans = 0; stack<int> st; for (int i = 0; i < N; i++){ if (S[i] == '('){ st.push(i); } if (S[i] == ')'){ if (st.top() == K){ ans = i; } if (i == K){ ans = st.top(); } st.pop(); } } cout << ans + 1 << endl; }