結果
問題 | No.281 門松と魔法(1) |
ユーザー |
![]() |
提出日時 | 2020-09-20 12:52:21 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 1,000 ms |
コード長 | 652 bytes |
コンパイル時間 | 210 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-06-24 10:42:28 |
合計ジャッジ時間 | 3,564 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines d=int(readline()) h=list(map(int, read().split())) INF=10**10 ans=INF import itertools for p in itertools.permutations(range(3)): if p[0]!=1 and p[2]!=1: continue x=h[:] if d==0: if x[p[0]]>x[p[1]] and x[p[1]]>x[p[2]]: print(0) exit() else: continue c1=max(0, (x[p[1]]-x[p[0]])//d+1) x[p[1]]-=c1*d if x[p[1]]<=0: continue c2=max(0, (x[p[2]]-x[p[1]])//d+1) x[p[2]]-=c2*d ans=min(ans, c1+c2) if ans==INF: print(-1) else: print(ans)