結果

問題 No.10 +か×か
コンテスト
ユーザー te-sh
提出日時 2016-09-21 17:40:00
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 117,888 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-06-12 04:31:11
合計ジャッジ時間 7,293 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 1 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto t = readln.chomp.to!int;
  auto ai = readln.split.map!(to!int);

  string rec(int t, string ops) {
    auto opsLen = ops.length;

    if (n - opsLen == 1)
      return t == ai[0] ? ops : "E";

    auto a = ai[n - opsLen - 1];
    if (t > a) {
      auto r1 = rec(t - a, "+" ~ ops);
      if (r1 != "E") return r1;
    }
    if (t % a == 0) {
      auto r2 = rec(t / a, "*" ~ ops);
      if (r2 != "E") return r2;
    }
    return "E";
  }

  writeln(rec(t, ""));
}
0