結果

問題 No.10 +か×か
コンテスト
ユーザー bal4u
提出日時 2019-04-08 16:19:10
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
TLE  
実行時間 -
コード長 773 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 201 ms
コンパイル使用メモリ 39,392 KB
最終ジャッジ日時 2026-02-22 02:50:53
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 2 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// 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