結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-01-16 01:18:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 518 bytes |
| コンパイル時間 | 651 ms |
| コンパイル使用メモリ | 78,428 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 06:56:17 |
| 合計ジャッジ時間 | 1,391 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
k--;
string s;
cin >> s;
int ans = -1;
stack<int> x;
for(int i=0; i<n; i++){
if(s[i] == '('){
x.push(i);
}else{
if(i==k){
ans = x.top();
}else if(x.top() == k){
ans = i;
}
x.pop();
}
}
cout << ans+1 << endl;
return 0;
}
koyumeishi