結果

問題 No.281 門松と魔法(1)
コンテスト
ユーザー ciel
提出日時 2015-10-29 05:38:11
言語 Crystal
(1.21.0 + ACL)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 543 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,013 ms
コンパイル使用メモリ 344,688 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-02 17:16:46
合計ジャッジ時間 10,568 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 38 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/env crystal
def solve_short(d,a,b,c)
	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=[0,b-r*d].max
	end
	a==b || b==c ? -1 : r
end
def solve_tall(d,a,b,c)
	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 ? -1 : r
end
d,a,b,c=4.times.map{gets.not_nil!.to_i}.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
0