結果

問題 No.592 括弧の対応 (2)
ユーザー Mayimg
提出日時 2019-01-22 11:53:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 232 ms / 5,000 ms
コード長 428 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 198,276 KB
最終ジャッジ日時 2025-01-06 20:33:56
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	stack<int> st;
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') st.push(i);
		else {
			int x = st.top();
			st.pop();
			ans[i] = x;
			ans[x] = i;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] + 1 << endl;
	}
	return 0;	
}
0