結果

問題 No.22 括弧の対応
ユーザー こるこる
提出日時 2017-02-17 18:07:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 68,524 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-29 07:16:05
合計ジャッジ時間 1,896 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,384 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VL vector<ll>
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define INF 1145141919810
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define TS(n) to_string(n)

using namespace std;


int main() {
	ll n, k;
	string s;
	cin >> n >> k >> s;
	k--;
	ll count = 0;
	ll index = 0;
	bool flag = false;
	rep(i, n){
		if (flag && s[i] == '(') count++;
		if (flag && s[i] == ')') count--;
		if (i == k){
			flag = true;
			count++;
		}if (flag && !count){
			cout << i + 1 << endl;
			break;
		}
	}
	return 0;
}
0