結果
問題 | No.592 括弧の対応 (2) |
ユーザー | face4 |
提出日時 | 2018-05-05 12:26:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 275 ms / 5,000 ms |
コード長 | 493 bytes |
コンパイル時間 | 601 ms |
コンパイル使用メモリ | 71,812 KB |
実行使用メモリ | 4,556 KB |
最終ジャッジ日時 | 2023-09-10 10:16:24 |
合計ジャッジ時間 | 2,145 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 275 ms
4,488 KB |
testcase_02 | AC | 271 ms
4,556 KB |
testcase_03 | AC | 270 ms
4,380 KB |
ソースコード
#include<iostream> #include<stack> using namespace std; int main(){ stack<int> st; int n; cin >> n; int A[n+1] = {}; string s; cin >> s; for(int i = 0; i < n; i++){ if(s[i] == '('){ st.push(i+1); }else if(s[i] == ')'){ int firstPos = st.top(); st.pop(); A[i+1] = firstPos; A[firstPos] = i+1; } } for(int i = 1; i <= n; i++){ cout << A[i] << endl; } return 0; }