結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-27 13:34:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 649 bytes |
| コンパイル時間 | 595 ms |
| コンパイル使用メモリ | 78,824 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:25:26 |
| 合計ジャッジ時間 | 1,237 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
//#include "util.h"
using namespace std;
typedef long long lint;
typedef pair<lint, lint> Pii;
int main()
{
int N, K;
string S;
cin >> N >> K >> S;
stack<int> st;
for (int i = 0; i < N; i++) {
if (S[i] == '(') {
st.push(i + 1);
}
else {
int l = st.top(), r = i + 1;
if (l == K || r == K) {
cout << (l == K ? r : l) << endl;
break;
}
st.pop();
}
}
return 0;
}