結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2017-02-08 15:26:28 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 77 ms / 5,000 ms |
コード長 | 636 bytes |
コンパイル時間 | 712 ms |
コンパイル使用メモリ | 101,788 KB |
実行使用メモリ | 82,508 KB |
最終ジャッジ日時 | 2024-06-12 06:59:00 |
合計ジャッジ時間 | 1,700 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 72 ms
81,392 KB |
testcase_04 | AC | 46 ms
53,952 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 77 ms
82,508 KB |
testcase_07 | AC | 54 ms
55,812 KB |
testcase_08 | AC | 13 ms
17,692 KB |
testcase_09 | AC | 16 ms
31,688 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
ソースコード
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); }