結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
kyo1
|
| 提出日時 | 2020-05-22 03:03:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 413 bytes |
| コンパイル時間 | 2,943 ms |
| コンパイル使用メモリ | 197,588 KB |
| 最終ジャッジ日時 | 2025-01-10 13:47:38 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
string S;
cin >> S;
vector<int> pos(N, 0);
stack<int> st;
for (int i = 0; i < N; i++) {
if (S[i] == '(') st.push(i);
if (S[i] == ')') {
pos[i] = st.top();
pos[st.top()] = i;
st.pop();
}
}
cout << pos[K - 1] + 1 << '\n';
return 0;
}
kyo1