結果
問題 | No.592 括弧の対応 (2) |
ユーザー | Julius Caesar |
提出日時 | 2017-11-10 23:04:14 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 241 ms / 5,000 ms |
コード長 | 477 bytes |
コンパイル時間 | 448 ms |
コンパイル使用メモリ | 61,736 KB |
実行使用メモリ | 4,580 KB |
最終ジャッジ日時 | 2023-08-16 03:52:23 |
合計ジャッジ時間 | 2,001 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 241 ms
4,480 KB |
testcase_02 | AC | 231 ms
4,580 KB |
testcase_03 | AC | 234 ms
4,380 KB |
ソースコード
#include <iostream> #include <string> #include <stack> int main(){ std::cin.tie(0); std::ios::sync_with_stdio(false); int N; std::string str; std::cin >> N >> str; int answer[200000] = {}; std::stack<int> stack; for(int i = 0; i < N; ++i){ if(str[i] == '('){ stack.push(i); } else{ answer[stack.top()] = i + 1; answer[i] = stack.top() + 1; stack.pop(); } } for(int i = 0; i < N; ++i){ std::cout << answer[i] << std::endl; } return 0; }