結果
問題 | No.592 括弧の対応 (2) |
ユーザー |
![]() |
提出日時 | 2017-11-10 22:25:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 239 ms / 5,000 ms |
コード長 | 664 bytes |
コンパイル時間 | 682 ms |
コンパイル使用メモリ | 78,540 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 12:29:23 |
合計ジャッジ時間 | 1,905 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <utility> #include <queue> #include <set> #include <map> #include <stack> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<VI> VVI; #define MP make_pair #define PB push_back #define inf 1000000007 int main(){ int n; cin >> n; string s; cin >> s; stack<int> st; vector<int> v(n); for(int i=0;i<n;i++){ if(s[i]=='('){ st.push(i); } if(s[i]==')'){ int x = st.top(); st.pop(); v[i] = x+1; v[x] = i+1; } } for(int i=0;i<n;i++){ cout << v[i] << endl; } return 0; }