結果

問題 No.10 +か×か
ユーザー ゴリポン先生ゴリポン先生
提出日時 2023-09-23 08:55:38
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 656 bytes
コンパイル時間 5,926 ms
コンパイル使用メモリ 204,916 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 08:55:52
合計ジャッジ時間 12,895 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

module main;

import std;

// 整数を(N - 1)桁の2進数に変換し、更に0を+、1を*に変換する
string toOps(int N, long x)
{
	return format("%0*b", N - 1, x).translate(['0' : '+', '1' : '*']);
}

void main()
{
	// 入力
	int N = readln.chomp.to!int;
	int total = readln.chomp.to!int;
	auto A = readln.split.to!(int[]);
	// 答えの計算(総当たり)
	long i = 0;
	for (; i < 2L ^^ (N - 1); i++) {
		auto ops = toOps(N, i);
		long val = A[0];
		foreach (j; 0 .. N - 1) {
			if (ops[j] == '+')
				val += A[j + 1];
			else	// ops[j] == '*'
				val *= A[j + 1];
		}
		if (val == total) break;
	}
	// 答えの出力
	writeln(toOps(N, i));
}
0