結果

問題 No.592 括弧の対応 (2)
ユーザー mtsdmtsd
提出日時 2017-11-10 22:25:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 245 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 77,300 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-08-16 02:56:46
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	stack<int> st;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		if(s[i]=='('){
			st.push(i);
		}
		if(s[i]==')'){
			int x = st.top();
			st.pop();
			v[i] = x+1;
			v[x] = i+1;
		}
	}
	for(int i=0;i<n;i++){
		cout << v[i] << endl;
	}

	return 0;
}
0