結果

問題 No.592 括弧の対応 (2)
ユーザー zaichu
提出日時 2017-11-11 20:01:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 692 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 172,480 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 19:26:45
合計ジャッジ時間 2,844 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> v(N);
    stack<int> st;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == '(')
        {
            st.push(i);
        }
        else
        {
            int tmp = st.top();
            v[i] = tmp;
            v[tmp] = i;
            st.pop();
        }
    }
    for (auto x : v)
    {
        cout << x + 1 << endl;
    }
}
0