結果

問題 No.592 括弧の対応 (2)
ユーザー MisterMister
提出日時 2020-04-15 22:58:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 573 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 77,692 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 19:03:24
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 247 ms
6,812 KB
testcase_02 AC 255 ms
6,944 KB
testcase_03 AC 247 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>

void solve() {
    int n;
    std::string s;
    std::cin >> n >> s;

    std::vector<int> stk;
    std::vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '(') {
            stk.push_back(i);

        } else {
            int j = stk.back();
            stk.pop_back();

            ans[i] = j, ans[j] = i;
        }
    }

    for (auto i : ans) std::cout << i + 1 << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0