結果

問題 No.592 括弧の対応 (2)
ユーザー ryoissyryoissy
提出日時 2017-11-10 22:26:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 440 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 147,296 KB
実行使用メモリ 4,696 KB
最終ジャッジ日時 2023-08-16 02:58:40
合計ジャッジ時間 1,809 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str;
int ans[200005];

int main(void){
	scanf("%d",&n);
	cin >> str;
	stack<int> sta;
	for(int i=0;i<n;i++){
		if(str[i]=='(')sta.push(i);
		else{
			int v=sta.top();
			sta.pop();
			ans[v]=i;
			ans[i]=v;
		}
	} 
	for(int i=0;i<n;i++){
		printf("%d\n",ans[i]+1);
	}
	return 0;
}
0