結果

問題 No.10 +か×か
ユーザー iicafiaxusiicafiaxus
提出日時 2018-12-07 22:31:48
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 1,529 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 118,588 KB
実行使用メモリ 23,704 KB
最終ジャッジ日時 2023-09-03 21:26:34
合計ジャッジ時間 1,542 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	int total = read.to!int;
	int[] as = readln.chomp.split.map!(to!int).array;
	
	int m = n / 2;
	
	uint[int] xs;
	xs[as[0]] = 0;
	foreach(a; as[1 .. m]){
		uint[int] xs_new;
		foreach(k; xs.keys){
			if(k + a <= total) if(k + a !in xs_new || xs_new[k + a] > xs[k] * 2 + 0) xs_new[k + a] = xs[k] * 2 + 0;
			if(k * a <= total) if(k * a !in xs_new || xs_new[k * a] > xs[k] * 2 + 1) xs_new[k * a] = xs[k] * 2 + 1;
		}
		xs = xs_new;
	}
	debug xs.writeln;
	
	uint[int] ys;
	ys[total] = 0;
	uint u = 1;
	foreach_reverse(a; as[m .. n]){
		uint[int] ys_new;
		foreach(k; ys.keys){
			if(k - a >= 0) if(k - a !in ys_new || ys_new[k - a] > 0 + ys[k]) ys_new[k - a] = 0 + ys[k];
			if(k % a == 0) if(k / a !in ys_new || ys_new[k / a] > u + ys[k]) ys_new[k / a] = u + ys[k];
		}
		ys = ys_new;
		u *= 2;
	}
	debug ys.writeln;
	
	int[uint] xrev;
	foreach(k; xs.keys) xrev[xs[k]] = k;
	uint[] vxs = xrev.keys;
	vxs.sort();
	int[] kxs;
	foreach(v; vxs) kxs ~= xrev[v];
	foreach(k; kxs){
		if(k in ys){
			string ans;
			foreach_reverse(i; 0 .. m - 1) if((1 << i) & xs[k]) ans ~= "*"; else ans ~= "+";
			foreach_reverse(i; 0 .. n - m) if((1 << i) & ys[k]) ans ~= "*"; else ans ~= "+";
			ans.writeln;
			break;
		}
	}
	return;
}
0