結果
問題 | No.592 括弧の対応 (2) |
ユーザー | tenman |
提出日時 | 2017-11-10 22:28:53 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 238 ms / 5,000 ms |
コード長 | 785 bytes |
コンパイル時間 | 921 ms |
コンパイル使用メモリ | 84,964 KB |
実行使用メモリ | 4,472 KB |
最終ジャッジ日時 | 2023-08-16 03:02:57 |
合計ジャッジ時間 | 2,496 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 234 ms
4,380 KB |
testcase_02 | AC | 238 ms
4,472 KB |
testcase_03 | AC | 236 ms
4,376 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; using ll = long long; using P = pair<int, int>; const int MAX = 2e5; const int INF = 1e9; const int MOD = 1e9 + 7; // 4近傍、8近傍 int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int c[MAX]; int main() { // 入力 int N; cin >> N; string s; cin >> s; stack<int> st; for (int i = 0; i < N; i++) { if (s[i] == '(') { st.push(i); } else { c[i] = st.top(); c[c[i]] = i; st.pop(); } } // 解答 for (int i = 0; i < N; i++) { cout << c[i] + 1 << endl; } return 0; }