結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2017-01-18 21:14:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 519 bytes |
コンパイル時間 | 774 ms |
コンパイル使用メモリ | 65,364 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:19:06 |
合計ジャッジ時間 | 1,808 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 16 |
ソースコード
#include <iostream>#include <string>#include <stack>#include <queue>int main(){int N; std::cin >> N;int K; std::cin >> K;std::string s; std::cin >> s;std::stack<int> st;std::queue<int> q;for(int i=0; i<s.size(); i++){if(s[i]=='(') st.push(i+1);else q.push(i+1);}while(!st.empty()){int i = st.top(); st.pop();int j = q.front(); q.pop();if(i==K){std::cout << j << std::endl;break;}else if(j==K){std::cout << i << std::endl;break;}}return 0;}