結果
問題 | No.592 括弧の対応 (2) |
ユーザー |
![]() |
提出日時 | 2020-12-28 21:56:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 5,000 ms |
コード長 | 599 bytes |
コンパイル時間 | 2,154 ms |
コンパイル使用メモリ | 199,672 KB |
最終ジャッジ日時 | 2025-01-17 07:55:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int N;cin >> N;string S;cin >> S;vector<int> res(N, 0);stack<pair<char, int>> st;for (int i = 0; i < N; i++) {if (st.empty()) {st.push(make_pair(S[i], i));} else {if (st.top().first == '(' && S[i] == ')') {int s = st.top().second;st.pop();res[s] = i;res[i] = s;} else {st.push(make_pair(S[i], i));}}}for (const auto &e : res) {cout << e + 1 << '\n';}return 0;}