結果

問題 No.592 括弧の対応 (2)
ユーザー uenoku
提出日時 2017-11-10 23:18:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 513 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 171,096 KB
実行使用メモリ 11,756 KB
最終ジャッジ日時 2024-11-24 15:17:36
合計ジャッジ時間 3,276 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    stack<int> st;
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans[2000005] = {};
    rep(i, n)
    {
        if (s[i] == '(')
            st.push(i);
        else {
            ans[i] = st.top();
            ans[st.top()] = i;
            st.pop();
        }
    }
    rep(i, n) cout << ans[i] + 1 << endl;
}
0