結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-22 20:20:02 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 720 bytes |
| コンパイル時間 | 2,767 ms |
| コンパイル使用メモリ | 279,116 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-22 20:20:07 |
| 合計ジャッジ時間 | 3,614 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
[[nodiscard]] static inline constexpr uint_fast32_t solve(const uint_fast32_t N, const uint_fast32_t K, const std::string& S) noexcept
{
std::vector<uint_least32_t> stack, pair_of(N);
stack.reserve(N / 2);
for (uint_fast32_t i = 0; i != N; ++i)
switch (S[i])
{
case '(':
stack.push_back(i);
break;
case ')':
[[assume(!stack.empty())]];
pair_of[i] = stack.back(), pair_of[stack.back()] = i;
stack.pop_back();
break;
}
return pair_of[K - 1] + 1;
}
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
uint_fast32_t N, K;
std::string S;
std::cin >> N >> K;
S.reserve(N), std::cin >> S;
std::cout << solve(N, K, S) << '\n';
return 0;
}