結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
weaken
|
| 提出日時 | 2020-10-09 12:04:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 5,000 ms |
| コード長 | 647 bytes |
| コンパイル時間 | 1,890 ms |
| コンパイル使用メモリ | 193,004 KB |
| 最終ジャッジ日時 | 2025-01-15 03:40:08 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
using namespace std;
class Stack {
public:
int stack[10000]{};
int top;
Stack() : top(0) {}
void push(int idx) { stack[top++] = idx; }
int pop() {
int p = stack[--top];
return p;
}
};
int main() {
fastIO;
Stack st;
int n, k;
string s;
cin >> n >> k >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == '(') {
st.push(i + 1);
} else {
int idx = st.pop();
if (idx == k) {
cout << i + 1 << '\n';
} else if (i + 1 == k) {
cout << idx << '\n';
}
}
}
return 0;
}
weaken