結果

問題 No.10 +か×か
ユーザー nebukuro09nebukuro09
提出日時 2016-11-04 22:07:17
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 800 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 97,360 KB
実行使用メモリ 9,056 KB
最終ジャッジ日時 2023-09-02 22:46:30
合計ジャッジ時間 3,055 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;

void main() {
  auto N = readln.chomp.to!int;
  auto T = readln.chomp.to!int;
  auto A = readln.split.map!(to!int).array;

  auto dp = new char[][](N, T+1);
  dp[0][A[0]] = '+';
  foreach (i; iota(N-1))
    foreach (j; iota(T+1)) {
      if (dp[i][j] != char.init) {
        if (j * A[i+1] <= T && dp[i+1][j*A[i+1]] == 0xFF)
          dp[i+1][j*A[i+1]] = '*';
        if (j + A[i+1] <= T)
          dp[i+1][j+A[i+1]] = '+';
      }
    }

  string ans = "";
  foreach (i; iota(N-1, 0, -1)) {
    ans = dp[i][T] ~ ans;
    if (dp[i][T] == '*')
      T /= A[i];
    else
      T -= A[i];
  }
  writeln(ans);
}
0