結果
問題 | No.592 括弧の対応 (2) |
ユーザー |
|
提出日時 | 2017-11-10 22:31:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 267 ms / 5,000 ms |
コード長 | 477 bytes |
コンパイル時間 | 927 ms |
コンパイル使用メモリ | 77,820 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 12:38:21 |
合計ジャッジ時間 | 2,213 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> #include <stack> using namespace std; int main() { int n; string s; cin >> n >> s; stack<int> st; vector<int> ans(n, -1); // 0-index for (int i = 0; i < n; i++) { if (s[i] == '(') { st.push(i); } else { int tmp = st.top(); ans[tmp] = i; ans[i] = tmp; st.pop(); } } for (auto x : ans) { cout << x + 1 << endl; } return 0; }