結果

問題 No.22 括弧の対応
ユーザー C_kumoC_kumo
提出日時 2019-01-21 18:40:57
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 479 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 28,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 22:25:04
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	short n,k,i,ans;
	char *c;
	scanf("%hd %hd",&n,&k);
	c = (char *)malloc(sizeof(char) * n);
	scanf("%s",c);

	if (c[k-1] == '(') {
		for (i=0;k-1<n;k++) {
			if      (c[k-1] == '(') i++;
			else if (c[k-1] == ')') i--;

			if (i<=0) break;
		}
	} else if (c[k-1] == ')') {
		for (;k-1>=0;k--) {
			if      (c[k-1] == ')') i++;
			else if (c[k-1] == '(') i--;

			if (i<=0) break;
		}
	}

	printf("%hd\n",k);

	return 0;
}
0