結果

問題 No.592 括弧の対応 (2)
ユーザー square1001square1001
提出日時 2017-11-10 23:12:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 362 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 71,096 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-08-16 05:11:18
合計ジャッジ時間 1,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 21 ms
4,376 KB
testcase_02 AC 21 ms
4,568 KB
testcase_03 AC 20 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stack>
#include <string>
#include <iostream>
using namespace std;
int n, ans[200009]; string s;
int main() {
	cin >> n >> s;
	stack<int> st;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') st.push(i);
		else {
			int v = st.top();
			st.pop();
			ans[i] = v;
			ans[v] = i;
		}
	}
	for (int i = 0; i < n; i++) cout << ans[i] + 1 << '\n';
	return 0;
}
0