結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-08 16:19:10 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 773 bytes |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 29,184 KB |
| 実行使用メモリ | 6,784 KB |
| 最終ジャッジ日時 | 2024-07-01 22:53:15 |
| 合計ジャッジ時間 | 11,188 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 7 |
ソースコード
// 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;
}
bal4u