結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
|
提出日時 | 2020-08-14 23:51:03 |
言語 | Crystal (1.14.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 11,802 ms |
コンパイル使用メモリ | 297,920 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 21:05:17 |
合計ジャッジ時間 | 13,197 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
def solve_short(d,a,b,c) begin r=0 if a==c c=[0,c-d].max r+=1 end t=b-[a,c].min+1 if t>0 cnt=(t+d-1)//d r+=cnt b=b > r.to_i64*d ? b-r*d : 0 end a==b || b==c ? -1 : r rescue DivisionByZeroError # changed in 0.25.0 -1 end end def solve_tall(d,a,b,c) begin r=0 t=a-b+1 if t>0 cnt=(t+d-1)//d r+=cnt a=[0,a-cnt*d].max end t=c-b+1 if t>0 cnt=(t+d-1)//d r+=cnt c=[0,c-cnt*d].max end if a==c c=[0,c-d].max r+=1 end a==b || b==c || c==a ? -1 : r rescue DivisionByZeroError # changed in 0.25.0 -1 end end d,a,b,c=(0...4).map{gets.not_nil!.to_i.to_i64}.to_a x=solve_short(d,a,b,c) y=solve_tall(d,a,b,c) p x>=0&&y>=0 ? [x,y].min : [x,y].max