結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
silopy
|
| 提出日時 | 2019-06-29 01:47:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 427 bytes |
| コンパイル時間 | 716 ms |
| コンパイル使用メモリ | 74,112 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:43:04 |
| 合計ジャッジ時間 | 1,401 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
using lint=int64_t;
int main()
{
int N,K;
string S;
cin >> N >> K;
cin >> S;
K--;
int ans=-1;
stack<int> s;
for(int i=0;i<S.size();i++)
{
if(S[i]=='(')
s.push(i);
else
{
if(i==K)
ans=s.top();
else
{
if(s.top()==K)
ans=i;
s.pop();
}
}
if(ans!=-1)
break;
}
cout << ans+1 << endl;
return 0;
}
silopy