結果

問題 No.592 括弧の対応 (2)
ユーザー rogi52rogi52
提出日時 2022-10-01 05:12:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 473 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 204,108 KB
実行使用メモリ 4,544 KB
最終ジャッジ日時 2023-08-24 22:35:57
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 19 ms
4,380 KB
testcase_02 AC 18 ms
4,544 KB
testcase_03 AC 18 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; string S; cin >> N >> S;
    stack<int> st;
    vector<int> ans(N, -1);
    rep(i,N) {
        if(S[i] == '(') st.push(i);
        else {
            int x = st.top(); st.pop();
            ans[x] = i;
            ans[i] = x;
        }
    }

    rep(i,N) cout << ans[i] + 1 << "\n";
}
0