結果

問題 No.319 happy b1rthday 2 me
ユーザー cielciel
提出日時 2015-12-13 03:18:38
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 507 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 11,360 KB
実行使用メモリ 15,476 KB
最終ジャッジ日時 2023-10-13 14:15:37
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 80 ms
15,208 KB
testcase_05 AC 80 ms
15,124 KB
testcase_06 AC 78 ms
15,244 KB
testcase_07 AC 79 ms
15,296 KB
testcase_08 AC 79 ms
15,248 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 79 ms
15,044 KB
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 80 ms
15,120 KB
testcase_20 AC 80 ms
15,108 KB
testcase_21 AC 84 ms
15,036 KB
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 79 ms
15,256 KB
testcase_30 WA -
testcase_31 AC 80 ms
15,020 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def perform(n,f)
	d=1
	d+=1 while 10**d<=n
	r=f&&(n+1)/10**(d-1)==2&&n%10==1 ? 1 : 0
	return r if n<2
	return r+1 if n<12

	(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)
	}
	if n%10**(d-1)>2
		r+=10**(d-2)
	elsif n%10**(d-1)==2
		r+=(n-2*10**(d-1))+(n%2>=10 ? 1 : 0)
	end
end
a,b=gets.split.map(&:to_i)
p perform(b,false)-perform(a-1,true)
0