結果

問題 No.592 括弧の対応 (2)
ユーザー gzlcpgzlcp
提出日時 2017-11-10 22:28:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 5,000 ms
コード長 884 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 97,276 KB
実行使用メモリ 5,608 KB
最終ジャッジ日時 2023-08-16 03:02:11
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 263 ms
5,268 KB
testcase_02 AC 259 ms
5,608 KB
testcase_03 AC 259 ms
5,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin>>n>>s;
	stack<ll> st;
	vector<ll> pos(n,0);
	REP(i,n) {
		if(s[i]=='(') st.push(i);
		else {
			ll p=st.top();
			st.pop();
			pos[i]=p;
			pos[p]=i;
		}
	}
	REP(i,n) cout<<pos[i]+1<<endl;
}

0