結果

問題 No.1961 Clear Brackets
ユーザー 👑 ygussanyygussany
提出日時 2022-05-27 22:52:57
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 764 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 30,700 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 20:35:25
合計ジャッジ時間 1,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main()
{
	int N;
	char S[200001];
	scanf("%d", &N);
	scanf("%s", S);
	
	int i, k, ans[2] = {};
	for (i = 0, k = 0; i < N; i++) {
		if (k == 0) {
			if (S[i] == '(') k = 2;
			else if (S[i] == '?') {
				if (S[i+1] == '?' || S[i+1] == ')') k = 2;
			}
		} else {
			if (S[i] == '(') k++;
			else {
				k--;
				if (k == 0) ans[0]++;
			}
		}
	}
	if (k == 1) ans[0]++;
	
	for (i = N - 1, k = 0; i >= 0; i--) {
		if (k == 0) {
			if (S[i] == ')') k = 2;
			else if (S[i] == '?') {
				if (i > 0 && (S[i-1] == '?' || S[i-1] == '(')) k = 2;
			}
		} else {
			if (S[i] == ')') k++;
			else {
				k--;
				if (k == 0) ans[1]++;
			}
		}
	}
	if (k == 1) ans[1]++;
	
	printf("%d\n", (ans[0] > ans[1])? ans[0]: ans[1]);
	fflush(stdout);
	return 0;
}
0