結果

問題 No.10 +か×か
ユーザー te-shte-sh
提出日時 2017-02-08 15:26:28
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 636 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 87,420 KB
実行使用メモリ 83,952 KB
最終ジャッジ日時 2023-09-03 01:25:11
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 75 ms
81,708 KB
testcase_04 AC 50 ms
54,152 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 87 ms
83,952 KB
testcase_07 AC 60 ms
54,152 KB
testcase_08 AC 14 ms
17,992 KB
testcase_09 AC 20 ms
31,328 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

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

  auto dp = new string[][](n, t + 1);
  auto calc(size_t i, int acc) {
    if (i == n) return acc == t ? "" : "E";
    if (acc > t) return "E";
    if (!dp[i][acc].empty) return dp[i][acc];

    auto r1 = calc(i + 1, acc + ai[i]);
    if (r1 != "E") return dp[i][acc] = "+" ~ r1;
    auto r2 = calc(i + 1, acc * ai[i]);
    if (r2 != "E") return dp[i][acc] = "*" ~ r2;

    return dp[i][acc] = "E";
  }

  auto r = calc(1, ai.front);
  writeln(r);
}
0