結果
| 問題 | No.592 括弧の対応 (2) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-10-02 23:05:42 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 26 ms / 5,000 ms | 
| コード長 | 706 bytes | 
| コンパイル時間 | 2,247 ms | 
| コンパイル使用メモリ | 198,852 KB | 
| 最終ジャッジ日時 | 2025-02-24 14:39:38 | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)s; i < (int)e; i++)
int main() {
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    
    stack<pair<char, int>> st;
    vector<int> ans(N);
    
    rep(i, 0, N) {
        char s;
        cin >> s;
        
        if (st.empty()) {
            st.push({s, i});
        } else {
            if (s == ')' && st.top().first == '(') {
                ans[st.top().second] = i;
                ans[i] = st.top().second;
                st.pop();
            } else {
                st.push({s, i});
            }
        }
    }
    
    rep(i, 0, N) {
        cout << ans[i] + 1 << '\n';
    }
}
            
            
            
        