結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
gasin
|
| 提出日時 | 2016-02-26 22:56:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 554 bytes |
| コンパイル時間 | 1,805 ms |
| コンパイル使用メモリ | 157,180 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:09:25 |
| 合計ジャッジ時間 | 2,472 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d%d",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int a, b;
string str;
int main(){
scanf("%d%d",&a, &b);
cin >> str;
b--;
int ans;
if(str[b] == '('){
int cnt = 1;
for(int i = b+1; i < a; i++){
if(str[i] == '('){
cnt++;
} else{
cnt--;
}
if(cnt == 0){
ans = i+1;
break;
}
}
} else{
int cnt = 1;
for(int i = b-1; i >= 0; i--){
if(str[i] == ')'){
cnt++;
} else{
cnt--;
}
if(cnt == 0){
ans = i+1;
break;
}
}
}
printf("%d\n", ans);
}
gasin