結果

問題 No.592 括弧の対応 (2)
ユーザー 🍮かんプリン
提出日時 2019-03-20 00:16:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 271 ms / 5,000 ms
コード長 603 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 67,860 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 14:40:28
合計ジャッジ時間 2,324 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
#define MOD 1000000007
using namespace std;

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