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