結果

問題 No.592 括弧の対応 (2)
ユーザー jimmyo0705jimmyo0705
提出日時 2017-11-10 22:28:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 247 ms / 5,000 ms
コード長 1,151 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 87,880 KB
実行使用メモリ 4,648 KB
最終ジャッジ日時 2023-08-16 03:01:17
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

int n;
string s;
vector<int> vi;
int ans[300000];

int main() {
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == '(')vi.push_back(i + 1);
		else {
			ans[i] = vi.back();
			ans[vi.back() - 1] = i + 1;
			vi.pop_back();
		}
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
}
0