結果

問題 No.158 奇妙なお使い
ユーザー te-shte-sh
提出日時 2018-07-12 14:20:52
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 1,154 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 91,348 KB
実行使用メモリ 50,616 KB
最終ジャッジ日時 2023-09-03 20:41:07
合計ジャッジ時間 3,072 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
48,356 KB
testcase_01 AC 24 ms
48,128 KB
testcase_02 AC 23 ms
47,328 KB
testcase_03 AC 23 ms
48,068 KB
testcase_04 AC 51 ms
50,616 KB
testcase_05 AC 24 ms
47,588 KB
testcase_06 AC 24 ms
48,852 KB
testcase_07 AC 23 ms
47,296 KB
testcase_08 AC 24 ms
48,052 KB
testcase_09 AC 23 ms
48,196 KB
testcase_10 AC 23 ms
47,804 KB
testcase_11 AC 23 ms
48,044 KB
testcase_12 AC 24 ms
48,608 KB
testcase_13 AC 23 ms
47,000 KB
testcase_14 AC 23 ms
47,624 KB
testcase_15 AC 24 ms
48,088 KB
testcase_16 AC 23 ms
47,620 KB
testcase_17 AC 25 ms
47,588 KB
testcase_18 AC 28 ms
48,836 KB
testcase_19 AC 23 ms
47,560 KB
testcase_20 AC 23 ms
47,812 KB
testcase_21 AC 24 ms
48,420 KB
testcase_22 AC 26 ms
50,200 KB
testcase_23 AC 24 ms
48,580 KB
testcase_24 AC 23 ms
47,672 KB
testcase_25 AC 24 ms
48,788 KB
testcase_26 AC 24 ms
47,776 KB
testcase_27 AC 23 ms
48,256 KB
testcase_28 AC 23 ms
47,832 KB
testcase_29 AC 23 ms
47,800 KB
testcase_30 AC 24 ms
48,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int at, ah, ao; readV(at, ah, ao);
  int db; readV(db);
  int bt, bh, bo; readV(bt, bh, bo);
  int dc; readV(dc);
  int ct, ch, co; readV(ct, ch, co);

  auto a = W(at, ah, ao), b = W(bt, bh, bo), c = W(ct, ch, co);

  auto m = new int[][][](11, 101, 10001);
  foreach (i; 0..11)
    foreach (j; 0..101)
      m[i][j][] = -1;

  int calc(W a)
  {
    if (a.t == -1) return -1;
    if (m[a.t][a.h][a.o] != -1)
      return m[a.t][a.h][a.o];

    auto ab = payAndGet(a, db, b);
    auto ac = payAndGet(a, dc, c);

    return m[a.t][a.h][a.o] = max(calc(ab), calc(ac))+1;
  }

  writeln(calc(a));
}

struct W { int t, h, o; }

auto payAndGet(W a, int p, W g)
{
  auto pt = min(p/1000, a.t);
  a.t -= pt;
  p -= pt*1000;

  auto ph = min(p/100, a.h);
  a.h -= ph;
  p -= ph*100;

  if (p > a.o) return W(-1, -1, -1);

  a.o -= p;

  return W(a.t+g.t, a.h+g.h, a.o+g.o);
}
0