結果
| 問題 | No.592 括弧の対応 (2) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-11-10 22:24:19 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 263 ms / 5,000 ms | 
| コード長 | 1,084 bytes | 
| コンパイル時間 | 1,775 ms | 
| コンパイル使用メモリ | 171,872 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-24 12:21:18 | 
| 合計ジャッジ時間 | 2,890 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 64;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string s;
    cin >> s;
    stack<int> st;
    vector<int> num(N, -1);
    for (int i = 0; i < N; i++) {
        if (s[i] == '(') {
            st.push(i);
        } else {
            const int p = st.top();
            st.pop();
            num[p] = i;
            num[i] = p;
        }
    }
    for (int i = 0; i < N; i++) {
        cout << num[i] + 1 << endl;
    }
    return 0;
}
            
            
            
        