結果
問題 | No.592 括弧の対応 (2) |
ユーザー | Kutimoti_T |
提出日時 | 2018-06-09 18:13:34 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 273 ms / 5,000 ms |
コード長 | 473 bytes |
コンパイル時間 | 1,160 ms |
コンパイル使用メモリ | 148,692 KB |
実行使用メモリ | 4,508 KB |
最終ジャッジ日時 | 2023-09-13 02:15:59 |
合計ジャッジ時間 | 2,803 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 273 ms
4,384 KB |
testcase_02 | AC | 271 ms
4,508 KB |
testcase_03 | AC | 268 ms
4,380 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) int main(){ int N; string s; cin >> N; cin >> s; vector<int> ans(N); stack<int> st; for(int i = 0;i < N;i++){ char c = s[i]; if(c == '('){ st.push(i); } else{ int j = st.top(); st.pop(); ans[j] = i; ans[i] = j; } } for(int i = 0;i < N;i++){ cout << ans[i] + 1 << endl; } }