結果
問題 | No.592 括弧の対応 (2) |
ユーザー |
|
提出日時 | 2017-11-10 22:26:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 23 ms / 5,000 ms |
コード長 | 440 bytes |
コンパイル時間 | 1,172 ms |
コンパイル使用メモリ | 164,024 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-24 12:30:42 |
合計ジャッジ時間 | 1,723 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d",&n); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>#define MOD 1000000007LLusing namespace std;typedef long long ll;typedef pair<int,int> P;int n;string str;int ans[200005];int main(void){scanf("%d",&n);cin >> str;stack<int> sta;for(int i=0;i<n;i++){if(str[i]=='(')sta.push(i);else{int v=sta.top();sta.pop();ans[v]=i;ans[i]=v;}}for(int i=0;i<n;i++){printf("%d\n",ans[i]+1);}return 0;}