結果

問題 No.22 括弧の対応
ユーザー kimaguremankimagureman
提出日時 2016-02-07 16:22:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 57,488 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 20:07:17
合計ジャッジ時間 1,173 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char** argv)
{
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;

	string ss = s.substr(k-1,1);
	if (ss==")") {
		int cnt = 0;
		string sss = s.substr(0, k-1);
		for (int ii=sss.size()-1; ii>=0; --ii) {
			if (sss[ii]==')') {
				++ cnt;
			}
			else if (cnt!=0) {
				-- cnt;
			}
			else {
				cout << (ii+1) << endl;
				return 0;
			}
		}
	}
	else {
		int cnt = 0;
		string sss = s.substr(k-1, s.size()-1);
		for (int ii=0; ii<sss.size(); ++ii) {
			if (sss[ii]=='(') {
				++ cnt;
			}
			else if (cnt!=0) {
				-- cnt;
			}
			else {
				cout << (k-1+ii) << endl;
				return 0;
			}
		}
	}
	return 0;
}
0