結果

問題 No.22 括弧の対応
ユーザー Sota
提出日時 2022-05-21 18:19:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 71,236 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-20 12:02:49
合計ジャッジ時間 1,381 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>		//cin, cout
#include <vector>		//vector
#include <algorithm>	//sort,min,max,count
#include <string>		//string,getline, to_string
#include <cstdlib>		//abs(int)
#include <utility>		//swap, pair
#include <deque>		//deque
#include <climits>		//INT_MAX
#include <bitset>		//bitset


using namespace std;

int main() {

	int N, K;
	string S;
	cin >> N >> K >> S;

	int i, j;

	while (1) {
		i = 0;
		while (S[i] != ')') {
			i++;
		}

		j = i - 1;
		while (S[j] != '(') {
			j--;
		}

		if (i == K - 1) {
			cout << j + 1 << endl;
			break;
		}
		else if (j == K - 1) {
			cout << i + 1 << endl;
			break;
		}
		else {
			S[i] = '0';
			S[j] = '0';
		}
	}

	return 0;

}
0