結果
問題 | No.592 括弧の対応 (2) |
ユーザー |
![]() |
提出日時 | 2017-11-10 22:28:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 243 ms / 5,000 ms |
コード長 | 1,081 bytes |
コンパイル時間 | 1,355 ms |
コンパイル使用メモリ | 164,072 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-11-24 12:34:15 |
合計ジャッジ時間 | 2,841 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define REP(i, n) rep(i, 0, n) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define int long long #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair<int, int> P; const int mod = 1000000007; const int INF = 1e12; vector<int> d[100010]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n; string s; cin >> n >> s; int now = 0; vector<P> id(n); rep(i, 0, n){ if(s[i] == '('){ id[i].first = now; id[i].second = d[now].size(); d[now].push_back(i); now++; }else{ now--; id[i].first = now; id[i].second = d[now].size(); d[now].push_back(i); } } rep(i, 0, n){ if(id[i].second % 2){ cout << d[id[i].first][id[i].second - 1] + 1 << endl; }else{ cout << d[id[i].first][id[i].second + 1] + 1<< endl; } } }