結果

問題 No.592 括弧の対応 (2)
ユーザー dnishdnish
提出日時 2018-06-18 14:33:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 5,000 ms
コード長 823 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 170,912 KB
実行使用メモリ 72,596 KB
最終ジャッジ日時 2023-09-13 06:46:07
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
70,928 KB
testcase_01 AC 316 ms
72,348 KB
testcase_02 AC 327 ms
72,472 KB
testcase_03 AC 321 ms
72,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define REP(i,n,N) for(int i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const int inf=1e9;

int N;
string s;
int ans[200020];
int cnt[200020];
queue<int> q[100010];
int main(){
    cin>>N>>s;
    cnt[0]=1;
    REP(i,1,N){
        if(s[i]=='('){
            cnt[i]=cnt[i-1]+1;
        }else{
            q[cnt[i-1]].push(i);
            cnt[i]=cnt[i-1]-1;
        }
    }
    REP(i,0,N){
        if(s[i]=='('){
            int op = q[cnt[i]].front();
            ans[i]=op+1;
            ans[op]=i+1;
            q[cnt[i]].pop();
        }
    }
    REP(i,0,N){
        p(ans[i]);
    }

}
0