結果

問題 No.319 happy b1rthday 2 me
ユーザー ciel
提出日時 2015-12-13 02:58:44
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 435 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-09-15 11:01:48
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def perform(n,f)
	d=1
	d+=1 while 10**d<=n
	r=n>1 ? 1 : 0
	(d-2).downto(0){|i|
		a,x=n.divmod(10**(i+2))
		b,c=x.divmod(10**(i+0))
		if b>12
			a+=1
			c=0
		elsif b<12
			c=0
		else
			c+=1
		end
		r+=a*10**i+c
	}
	1.upto(d-1){|i|
		r+=i<3 ? 1 : 10**(i-2)
	}
	r+=(n-2*10**(d-1)-2+10)/10 if n/10**(d-1)>=2
	n+=1
	r+(f&&n/10**(d-1)==2&&n%10==2 ? 1 : 0)
end
a,b=gets.split.map(&:to_i)
p perform(b,false)-perform(a-1,true)
0