結果
問題 | No.592 括弧の対応 (2) |
ユーザー |
![]() |
提出日時 | 2017-11-10 22:26:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 237 ms / 5,000 ms |
コード長 | 678 bytes |
コンパイル時間 | 723 ms |
コンパイル使用メモリ | 82,856 KB |
実行使用メモリ | 6,656 KB |
最終ジャッジ日時 | 2024-11-24 12:30:10 |
合計ジャッジ時間 | 1,739 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <string>#include <iomanip>#include <algorithm>#include <cmath>#include <stdio.h>using namespace std;#define int long longint MOD = 1000000007;signed main() {cin.tie(0);ios::sync_with_stdio(false);int N;string S;cin >> N;cin >> S;vector<int> A(N, -1);vector<int> res(N, -1);int cur = 0;for (int i = 0; i < N; i++) {if (S[i] == '(') {A[cur] = i;cur++;}else {cur--;res[i] = A[cur];}}for (int i = 0; i < N; i++) {if (res[i] != -1) {res[res[i]] = i;}}for (int i = 0; i < N; i++) {cout << res[i] + 1 << endl;}}