結果

問題 No.684 Prefix Parenthesis
ユーザー kriiikriii
提出日時 2018-12-12 18:44:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 370 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 31,664 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-25 08:32:47
合計ジャッジ時間 1,387 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 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 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 WA -
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int N;
char S[100100];

int main()
{
	scanf ("%d %s",&N,S+1);

	long long ab = 0, amn = 0, b = 0, mn = 0;
	for (int i=1;i<=N;i++){
		if (S[i] == '(') b++;
		else{
			b--;
			if (mn > b) mn = b;
		}

		if (amn > ab + mn)
			amn = ab + mn;
		ab += b;
	}

	long long len = (long long)N * (N + 1) / 2 - ab + 2 * amn;
	printf ("%lld\n",len);

	return 0;
}
0