結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
miku39kk
|
| 提出日時 | 2017-08-01 11:58:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 706 bytes |
| コンパイル時間 | 597 ms |
| コンパイル使用メモリ | 64,484 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:25:02 |
| 合計ジャッジ時間 | 1,221 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
int n,k;
string s;
cin >> n >> k >> s;
int ans = 0;
if(s[k-1] == '('){
for(int i = k-1;i < n;i++){
if(s[i] == '(')ans++;
else ans--;
if(ans == 0){
ans = i+1;
break;
}
}
}
else{
for(int i = k-1;i >= 0;i--){
if(s[i] == '(')ans++;
else ans--;
if(ans == 0){
ans = i+1;
break;
}
}
}
cout << ans << endl;
return 0;
}
miku39kk