結果
問題 | No.592 括弧の対応 (2) |
ユーザー | HIR180 |
提出日時 | 2017-11-10 22:25:47 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 23 ms / 5,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 1,137 ms |
コンパイル使用メモリ | 147,556 KB |
実行使用メモリ | 4,692 KB |
最終ジャッジ日時 | 2023-08-16 02:56:57 |
合計ジャッジ時間 | 1,845 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 21 ms
4,592 KB |
testcase_02 | AC | 22 ms
4,692 KB |
testcase_03 | AC | 23 ms
4,512 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) string s; int n; int ans[1000005]; int main(){ cin>>n>>s; stack<int>S; rep(i,n){ if(s[i]=='('){ S.push(i+1); } else{ int x = S.top(); S.pop(); ans[x] = i+1; ans[i+1] = x; } } repn(i,n) printf("%d\n",ans[i]); }