結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2015-10-29 01:32:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 507 bytes |
| コンパイル時間 | 544 ms |
| コンパイル使用メモリ | 65,484 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:04:42 |
| 合計ジャッジ時間 | 1,237 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<iostream>
#include<stdio.h>
#include<stack>
#include<vector>
using namespace std;
int main(){
int n, k;
string str;
scanf("%d %d", &n, &k);
cin>> str;
stack<int> st;
vector<int> arr(n);
int num = 0;
for(int i=0; i<n; i++){
if(str[i] == '('){
st.push(i);
}else{
num = st.top();
st.pop();
arr[i] = num;
arr[num] = i;
}
}
cout<< arr[k-1] + 1<< endl;
return 0;
}
ikd