結果

問題 No.158 奇妙なお使い
ユーザー te-shte-sh
提出日時 2016-09-08 12:41:42
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 1,825 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 106,496 KB
実行使用メモリ 66,236 KB
最終ジャッジ日時 2023-09-02 22:00:01
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
12,348 KB
testcase_01 AC 47 ms
32,072 KB
testcase_02 AC 8 ms
6,380 KB
testcase_03 AC 67 ms
51,520 KB
testcase_04 AC 102 ms
66,236 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 82 ms
62,892 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 38 ms
28,488 KB
testcase_09 AC 75 ms
56,236 KB
testcase_10 AC 74 ms
54,836 KB
testcase_11 AC 75 ms
57,740 KB
testcase_12 AC 47 ms
32,556 KB
testcase_13 AC 47 ms
33,884 KB
testcase_14 AC 70 ms
53,396 KB
testcase_15 AC 86 ms
62,608 KB
testcase_16 AC 86 ms
62,588 KB
testcase_17 AC 84 ms
62,376 KB
testcase_18 AC 49 ms
33,068 KB
testcase_19 AC 64 ms
51,820 KB
testcase_20 AC 76 ms
56,236 KB
testcase_21 AC 84 ms
62,888 KB
testcase_22 AC 83 ms
63,348 KB
testcase_23 AC 75 ms
56,228 KB
testcase_24 AC 83 ms
62,388 KB
testcase_25 AC 72 ms
54,144 KB
testcase_26 AC 38 ms
27,444 KB
testcase_27 AC 51 ms
34,060 KB
testcase_28 AC 60 ms
38,988 KB
testcase_29 AC 47 ms
32,032 KB
testcase_30 AC 54 ms
34,660 KB
権限があれば一括ダウンロードができます

ソースコード

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 rd1 = readln.split.map!(to!int);
  auto a3 = rd1[0], a2 = rd1[1], a0 = rd1[2];
  auto db = readln.chomp.to!int;
  auto rd2 = readln.split.map!(to!int);
  auto b3 = rd2[0], b2 = rd2[1], b0 = rd2[2];
  auto dc = readln.chomp.to!int;
  auto rd3 = readln.split.map!(to!int);
  auto c3 = rd3[0], c2 = rd3[1], c0 = rd3[2];

  auto at = total(a3, a2, a0), maxA3 = at / 1000, maxA2 = at / 100;
  auto bt = total(b3, b2, b0);
  auto ct = total(c3, c2, c0);

  auto memo = new int[][][](at + 1, maxA3 + 1, maxA2 + 1);
  memo[total(a3, a2, a0)][a3][a2] = 1;

  void pay(int d, int i, int j, int k, int et, int e3, int e2) {
    if (canPay(d, i, j, k)) {
      auto i2 = i - d;
      auto jp = min(d / 1000, j);
      auto j2 = j - jp;
      auto k2 = k - min((d - jp * 1000) / 100, k);
      memo[i2 + et][j2 + e3][k2 + e2] = max(memo[i2 + et][j2 + e3][k2 + e2], memo[i][j][k] + 1);
    }
  }

  foreach_reverse (i; 1..at + 1)
    foreach (j; 0..maxA3 + 1)
      foreach (k; 0..maxA2 + 1)
        if (memo[i][j][k]) {
          pay(db, i, j, k, bt, b3, b2);
          pay(dc, i, j, k, ct, c3, c2);
        }

  auto maxC = 0;
  foreach (i; 1..at + 1)
    foreach (j; 0..maxA3 + 1)
      foreach (k; 0..maxA2 + 1)
        maxC = max(maxC, memo[i][j][k]);

  writeln(maxC - 1);
}

int total(int a3, int a2, int a0)
{
  return a3 * 1000 + a2 * 100 + a0;
}

bool canPay(int d, int i, int j, int k)
{
  auto a3 = j, a2 = k, a0 = i - j * 1000 - k * 100;

  if (d > i) return false;

  if (d % 100 > a0) return false;
  a0 -= d % 100;
  a2 += a0 / 100;
  d /= 100;

  if (d % 10 > a2) return false;

  return true;
}
0