結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2020-07-23 08:06:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 353 bytes |
コンパイル時間 | 2,010 ms |
コンパイル使用メモリ | 198,976 KB |
最終ジャッジ日時 | 2025-01-12 04:08:58 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; cin >> N >> K >> S; K--; vector V(N, 0); stack<int> ST; for (int i = 0; i < N; i++) { if (S.at(i) == '(') ST.push(i); else { int top = ST.top(); ST.pop(); V.at(i) = top; V.at(top) = i; } } cout << V.at(K) + 1 << "\n"; }