結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
miku39kk
|
| 提出日時 | 2017-08-01 11:58:48 |
| 言語 | C++11 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 5,000 ms |
| + 47µs | |
| コード長 | 706 bytes |
| 記録 | |
| コンパイル時間 | 532 ms |
| コンパイル使用メモリ | 91,604 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-11-10 19:11:19 |
| 合計ジャッジ時間 | 2,123 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#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