結果
| 問題 |
No.592 括弧の対応 (2)
|
| コンテスト | |
| ユーザー |
dnish
|
| 提出日時 | 2018-06-18 14:33:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 333 ms / 5,000 ms |
| コード長 | 823 bytes |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 173,548 KB |
| 実行使用メモリ | 72,580 KB |
| 最終ジャッジ日時 | 2024-06-30 16:53:53 |
| 合計ジャッジ時間 | 3,845 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
#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]);
}
}
dnish