結果

問題 No.281 門松と魔法(1)
ユーザー mkawa2
提出日時 2020-02-05 22:24:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 1,000 ms
コード長 1,558 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-09-23 04:22:23
合計ジャッジ時間 3,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
def main():
def iskado(hh):
if (hh[0]>hh[1]<hh[2] or hh[0]<hh[1]>hh[2]) and hh[0]!=hh[2]:
return True
else:return False
inf=10**12
d=II()
a=II()
b=II()
c=II()
hh=[a,b,c]
if hh.count(0)>1:
print(-1)
exit()
if d==0:
if iskado(hh):print(0)
else:print(-1)
exit()
#
cnt1=0
for i in [0,2]:
k=max((hh[i]-hh[1]+d)//d,0)
cnt1+=k
hh[i]=max(hh[i]-d*k,0)
if hh[0]==hh[2]:
hh[0]=max(hh[0]-d,0)
cnt1+=1
if not iskado(hh):cnt1=inf
#
hh=[a,b,c]
cnt2=0
if hh[0]==hh[2]:
hh[0]=max(hh[0]-d,0)
cnt2 += 1
k=max((hh[1]-min(hh[0],hh[2])+d)//d,0)
cnt2+=k
hh[1]=max(hh[1]-d*k,0)
if not iskado(hh):cnt2=inf
ans=min(cnt1,cnt2)
if ans==inf:print(-1)
else:print(ans)
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0