結果

問題 No.592 括弧の対応 (2)
ユーザー ukohank517ukohank517
提出日時 2017-11-10 22:27:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 5,000 ms
コード長 1,166 bytes
コンパイル時間 4,050 ms
コンパイル使用メモリ 95,612 KB
実行使用メモリ 5,668 KB
最終ジャッジ日時 2023-08-16 03:00:16
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stack>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

ll ans[200001];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N ;cin >> N;
  string str ;cin >> str;
  stack<ll> s;
  rep(i,N){
    if(str[i] =='(')
      s.push(i);
    else{
      ll left = s.top();
      s.pop();
      ans[left] = i;
      ans[i] = left;
    }
  }
  rep(i,N)cout << ans[i]+1 << endl;

  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}
0