結果

問題 No.10 +か×か
ユーザー iicafiaxusiicafiaxus
提出日時 2018-12-07 21:57:37
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 115,404 KB
実行使用メモリ 655,296 KB
最終ジャッジ日時 2023-09-03 21:25:43
合計ジャッジ時間 8,461 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(){
	long n = read.to!long;
	long total = read.to!long;
	long[] as = readln.chomp.split.map!(to!long).array;
	
	long m = (n + 1) / 2;
	
	string[long] xs;
	xs[as[0]] = "";
	foreach(a; as[1 .. m]){
		string[long] xs_new;
		foreach(k; xs.keys){
			if(k + a !in xs_new || xs_new[k + a] < xs[k] ~ "+") xs_new[k + a] = xs[k] ~ "+";
			if(k * a !in xs_new || xs_new[k * a] < xs[k] ~ "*") xs_new[k * a] = xs[k] ~ "*";
		}
		xs = xs_new;
	}
	debug xs.writeln;
	
	string[long] ys;
	ys[total] = "";
	foreach_reverse(a; as[m .. n]){
		string[long] ys_new;
		foreach(k; ys.keys){
			if(k - a !in ys_new || ys_new[k - a] < "+" ~ ys[k]) ys_new[k - a] = "+" ~ ys[k];
			if(k % a == 0) if(k / a !in ys_new || ys_new[k / a] < "*" ~ ys[k]) ys_new[k / a] = "*" ~ ys[k];
		}
		ys = ys_new;
	}
	debug ys.writeln;
	
	long[] kxs = xs.keys;
	foreach(k; kxs){
		if(k in ys){
			(xs[k] ~ ys[k]).writeln;
			break;
		}
	}
	return;
}
0