結果

問題 No.592 括弧の対応 (2)
ユーザー MayimgMayimg
提出日時 2019-01-22 11:53:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 5,000 ms
コード長 428 bytes
コンパイル時間 2,673 ms
コンパイル使用メモリ 204,076 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-13 17:38:19
合計ジャッジ時間 4,161 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 237 ms
4,352 KB
testcase_02 AC 235 ms
4,476 KB
testcase_03 AC 237 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

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