結果

問題 No.10 +か×か
ユーザー bal4ubal4u
提出日時 2019-04-08 16:19:10
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 773 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 28,844 KB
実行使用メモリ 5,880 KB
最終ジャッジ日時 2023-09-14 15:42:45
合計ジャッジ時間 10,775 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.10 +か×か
// 2019.4.8 bal4u
// 全検索

#include <stdio.h>

#if 0
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void outs(char *s) { while (*s) pc(*s++); }

int a[55];
char ans[55];
int N, total;

int calc(int id, int val)
{
	int res;

	if (id >= N) return (val == total);

	res = val + a[id], ans[id] = '+';
	if (calc(id + 1, res)) return 1;

	res = val * a[id], ans[id] = '*';
	if (calc(id + 1, res)) return 1;
	return 0;
}

int main()
{
	int i;
	N = in(), total = in();
	for (i = 0; i < N; i++) a[i] = in();
	calc(1, a[0]);
	outs(ans + 1), pc('\n');
	return 0;
}
0