結果
| 問題 | 
                            No.10 +か×か
                             | 
                    
| コンテスト | |
| ユーザー | 
                             iicafiaxus
                         | 
                    
| 提出日時 | 2018-12-07 22:40:40 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,140 bytes | 
| コンパイル時間 | 804 ms | 
| コンパイル使用メモリ | 126,208 KB | 
| 実行使用メモリ | 37,248 KB | 
| 最終ジャッジ日時 | 2024-06-13 02:05:01 | 
| 合計ジャッジ時間 | 2,998 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 WA * 5 | 
ソースコード
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;
	
	
	// そうか…
	// 半分全列挙にしてたけど、枝刈りをちゃんとやれば単に前からやるだけでいいのか…
	// (それか後ろからなら割り算で割り切れるという制約がつくのでもっと楽…?)
	uint[int] xs;
	xs[as[0]] = 0;
	foreach(a; as[1 .. n]){
		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;
	
	if(total in xs){
		string ans;
		foreach_reverse(i; 0 .. n - 1) if((1 << i) & xs[total]) ans ~= "*"; else ans ~= "+";
		ans.writeln;
	}
}
            
            
            
        
            
iicafiaxus