結果
| 問題 | 
                            No.10 +か×か
                             | 
                    
| コンテスト | |
| ユーザー | 
                             iicafiaxus
                         | 
                    
| 提出日時 | 2018-12-07 22:06:21 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,357 bytes | 
| コンパイル時間 | 716 ms | 
| コンパイル使用メモリ | 127,652 KB | 
| 実行使用メモリ | 812,980 KB | 
| 最終ジャッジ日時 | 2024-06-13 02:04:13 | 
| 合計ジャッジ時間 | 7,692 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 MLE * 1 -- * 8 | 
ソースコード
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(){
	long n = read.to!long;
	long total = read.to!long;
	long[] as = readln.chomp.split.map!(to!long).array;
	
	long m = n / 2;
	
	long[long] xs;
	xs[as[0]] = 0;
	foreach(a; as[1 .. m]){
		long[long] xs_new;
		foreach(k; xs.keys){
			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 !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;
	
	long[long] ys;
	ys[total] = 0;
	foreach_reverse(a; as[m .. n]){
		long[long] ys_new;
		foreach(k; ys.keys){
			if(k - a !in ys_new || ys_new[k - a] > ys[k] * 2 + 0) ys_new[k - a] = ys[k] * 2 + 0;
			if(k % a == 0) if(k / a !in ys_new || ys_new[k / a] > ys[k] * 2 + 1) ys_new[k / a] = ys[k] * 2 + 1;
		}
		ys = ys_new;
	}
	debug ys.writeln;
	
	long[] kxs = xs.keys;
	foreach(k; kxs){
		if(k in ys){
			string ans;
			foreach_reverse(i; 0 .. m - 1) if((1 << i) & xs[k]) ans ~= "*"; else ans ~= "+";
			foreach(i; 0 .. n - m) if((1 << i) & ys[k]) ans ~= "*"; else ans ~= "+";
			ans.writeln;
			break;
		}
	}
	return;
}
            
            
            
        
            
iicafiaxus