結果

問題 No.592 括弧の対応 (2)
ユーザー Mister
提出日時 2020-04-15 22:58:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 292 ms / 5,000 ms
コード長 573 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 73,836 KB
最終ジャッジ日時 2025-01-09 19:21:48
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

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