結果
問題 | No.592 括弧の対応 (2) |
ユーザー | Pachicobue |
提出日時 | 2017-11-10 22:24:19 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 239 ms / 5,000 ms |
コード長 | 1,084 bytes |
コンパイル時間 | 1,668 ms |
コンパイル使用メモリ | 170,684 KB |
実行使用メモリ | 4,468 KB |
最終ジャッジ日時 | 2023-08-16 02:47:29 |
合計ジャッジ時間 | 2,750 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 237 ms
4,380 KB |
testcase_02 | AC | 239 ms
4,468 KB |
testcase_03 | AC | 235 ms
4,376 KB |
ソースコード
#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; }