結果
問題 | No.281 門松と魔法(1) |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
import syssys.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) - 1def 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 Trueelse:return Falseinf=10**12d=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=0for i in [0,2]:k=max((hh[i]-hh[1]+d)//d,0)cnt1+=khh[i]=max(hh[i]-d*k,0)if hh[0]==hh[2]:hh[0]=max(hh[0]-d,0)cnt1+=1if not iskado(hh):cnt1=inf# 真ん中を最小にする場合hh=[a,b,c]cnt2=0if hh[0]==hh[2]:hh[0]=max(hh[0]-d,0)cnt2 += 1k=max((hh[1]-min(hh[0],hh[2])+d)//d,0)cnt2+=khh[1]=max(hh[1]-d*k,0)if not iskado(hh):cnt2=infans=min(cnt1,cnt2)if ans==inf:print(-1)else:print(ans)main()