結果

問題 No.281 門松と魔法(1)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-07-17 06:11:38
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,035 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 68,392 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 01:01:22
合計ジャッジ時間 5,813 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import strutils

const INF = int(1e9) + 100

var
  d  = stdin.readLine.parseInt
  h1 = stdin.readLine.parseInt
  h2 = stdin.readLine.parseInt
  h3 = stdin.readLine.parseInt

proc bye(x: int) = echo(x); quit 0

proc ok(x, y, z: int): bool =
  var
    ok1 = x > y and y < z
    ok2 = x < y and y > z
  result = x != z and (ok1 or ok2)

proc count(my, your, d: int): int =
  if your == 0: return INF
  if my < your: return 0
  result = (my - your + d) div d

proc cut(my, d, times: int): int =
  result = max(0, my-d*times)

if ok(h1, h2, h3):
  bye(0)
if d == 0:
  bye(-1)

var x, y, z, p, q: int

var r1 = 0
x = h1
y = h2
z = h3
if x == z:
  x = cut(x, d, 1)
  r1 += 1
p = count(x, y, d)
r1 += p
x = cut(x, d, p)
q = count(z, y, d)
r1 += q
z = cut(z, d, q)
if not ok(x, y, z):
  r1 = INF

var r2 = 0
x = h1
y = h2
z = h3
if x == z:
  x = cut(x, d, 1)
  r2 += 1
p = count(y, x, d)
r2 += p
y = cut(y, d, p)
q = count(y, z, d)
r2 += q
y = cut(y, d, q)
if not ok(x, y, z):
  r2 = INF

var res = min(r1, r2)
if res >= INF: res = -1
echo res
0