結果

問題 No.22 括弧の対応
ユーザー Kenichi Higashide
提出日時 2016-07-07 09:35:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 415 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 64,060 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:13:57
合計ジャッジ時間 1,228 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[])
{
	int n, k;
	cin >> n >> k;
	cin.setf(ios_base::skipws);
	string s;
	cin >> s;
	int position = k;
	int direction = ((s[position - 1] == '(') ? 1 : -1);
	int depth = direction;
	do {
		position += direction;
		depth += ((s[position - 1] == '(') ? 1 : -1);
	} while (depth != 0);

	cout << position << endl;

	return 0;
}
0