結果

問題 No.10 +か×か
ユーザー te-shte-sh
提出日時 2016-09-21 17:40:00
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 106,308 KB
実行使用メモリ 8,108 KB
最終ジャッジ日時 2023-09-02 22:18:33
合計ジャッジ時間 8,032 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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