結果
問題 |
No.22 括弧の対応
|
ユーザー |
|
提出日時 | 2016-08-08 00:05:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 531 bytes |
コンパイル時間 | 788 ms |
コンパイル使用メモリ | 65,340 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:14:44 |
合計ジャッジ時間 | 1,326 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <stack> #include <vector> auto main() -> int { int N; int K; std::string S; std::cin >> N >> K >> S; std::vector<int> corresponing_indexes(N); std::stack<int> stack; int left, right; for (int i = 0; i < N; ++i) { switch (S[i]) { case '(': stack.push(i); break; case ')': left = stack.top(); right = i; corresponing_indexes[left] = right; corresponing_indexes[right] = left; stack.pop(); break; } } std::cout << corresponing_indexes[K-1]+1 << std::endl; }