結果

問題 No.281 門松と魔法(1)
ユーザー yuruhiyayuruhiya
提出日時 2020-10-31 10:46:27
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 838 bytes
コンパイル時間 18,904 ms
コンパイル使用メモリ 253,540 KB
実行使用メモリ 813,352 KB
最終ジャッジ日時 2023-09-13 12:34:03
合計ジャッジ時間 22,854 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,488 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,476 KB
testcase_04 AC 2 ms
4,388 KB
testcase_05 AC 3 ms
4,424 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,412 KB
testcase_10 AC 2 ms
4,396 KB
testcase_11 AC 3 ms
4,480 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,408 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,464 KB
testcase_18 AC 2 ms
4,424 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,444 KB
testcase_24 AC 2 ms
4,388 KB
testcase_25 WA -
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 3 ms
4,436 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,420 KB
testcase_30 AC 2 ms
4,436 KB
testcase_31 RE -
testcase_32 AC 3 ms
4,476 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
4,500 KB
testcase_37 RE -
testcase_38 AC 2 ms
4,432 KB
testcase_39 AC 2 ms
4,448 KB
testcase_40 RE -
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 MLE -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

# a -> less than b
def calc(a, b, d)
  if a < b
    0
  else
    (a - b) // d + 1
  end
end

def solve(a, b, c, d)
  a, b, c = [a, b, c].map { |i| {i, 0}.max }
  if [a, b, c].count { |i| i == 0 } >= 2
    Int32::MAX
  elsif a == b
    {1 + solve(a - d, b, c, d), 1 + solve(a, b - d, c, d)}.min
  elsif a == c
    {1 + solve(a - d, b, c, d), 1 + solve(a, b, c - d, d)}.min
  elsif b == c
    {1 + solve(a, b - d, c, d), 1 + solve(a, b, c - d, d)}.min
  else
    if (b > a && b > c) || (b < a && b < c)
      0
    else
      {calc(a, b, d) + calc(c, b, d), calc(b, {a, c}.min, d)}.min
    end
  end
end

d, a, b, c = (1..4).map { read_line.to_i }
ans = solve(a, b, c, d)
puts ans < Int32::MAX ? ans : -1
0