結果

問題 No.319 happy b1rthday 2 me
ユーザー 小指が強い人小指が強い人
提出日時 2015-12-12 17:48:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 2,442 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 11,472 KB
実行使用メモリ 15,332 KB
最終ジャッジ日時 2023-08-27 00:12:17
合計ジャッジ時間 5,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,332 KB
testcase_01 AC 86 ms
15,172 KB
testcase_02 AC 84 ms
15,140 KB
testcase_03 AC 84 ms
15,244 KB
testcase_04 AC 85 ms
15,008 KB
testcase_05 AC 83 ms
15,260 KB
testcase_06 AC 84 ms
15,140 KB
testcase_07 AC 84 ms
15,328 KB
testcase_08 AC 84 ms
15,216 KB
testcase_09 AC 83 ms
15,120 KB
testcase_10 AC 83 ms
15,012 KB
testcase_11 AC 82 ms
15,264 KB
testcase_12 AC 82 ms
15,072 KB
testcase_13 AC 83 ms
15,124 KB
testcase_14 AC 82 ms
15,032 KB
testcase_15 AC 82 ms
15,128 KB
testcase_16 AC 83 ms
15,132 KB
testcase_17 AC 86 ms
15,264 KB
testcase_18 AC 85 ms
15,288 KB
testcase_19 AC 85 ms
15,252 KB
testcase_20 AC 85 ms
15,284 KB
testcase_21 AC 84 ms
15,204 KB
testcase_22 AC 84 ms
15,272 KB
testcase_23 AC 85 ms
15,280 KB
testcase_24 AC 84 ms
15,008 KB
testcase_25 AC 85 ms
15,012 KB
testcase_26 AC 84 ms
15,128 KB
testcase_27 AC 83 ms
15,132 KB
testcase_28 AC 82 ms
15,076 KB
testcase_29 AC 83 ms
15,280 KB
testcase_30 AC 84 ms
15,168 KB
testcase_31 AC 83 ms
15,100 KB
testcase_32 AC 83 ms
15,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:19: warning: assigned but unused variable - an
Main.rb:19: warning: assigned but unused variable - bn
Main.rb:23: warning: assigned but unused variable - ch
Main.rb:24: warning: assigned but unused variable - ss
Syntax OK

ソースコード

diff #

#happy b1rthday 2 me
def comb(n, m)
    q = 1
    m.times do |x|
        q *= n - x
        q /= (x + 1)
    end
    return q
end
a, b = gets.split
if a == b
    count = 0
    (a.length - 1).times do |i|
        count += 1 if a[i, 2] == "12"
    end
    puts count
    exit
end
an, bn = a.to_i, b.to_i
la = a.length
lb = b.length
res = 0
ch = 0
ss = ""
=begin
(a.to_i).upto(b.to_i) do |x|
    ss += x.to_s
end
(ss.length - 1).times do |i|
    ch += 1 if ss[i, 2].to_i == 12
end
puts ch
=end
la.upto(lb) do |x|
    if x == 1
        res += 1
        next
    end
    d = x - 2
    res += 10 ** d
    res += d * 9 * 10 ** (d - 1) if d > 0
    if x >= 3
        res += 10 ** (x - 2)
    else
        res += 1
    end
end
y = 2
(la - y).downto(0) do |i|
    j = la - i - y
    q = 0
    mid = a[i, y].to_i
    left = a[0, i].to_i
    right = a[i + y, j].to_i
    if i == 0
        if mid > 12
            q += 10 ** j
        elsif mid == 12
            q += right
        end
    elsif i == la - y
        q += left - 10 ** (i - 1)
        q += 1 if mid > 12
    else
        if mid > 12
            q += (left - 10 ** (i - 1) + 1) * 10 ** j
        elsif mid < 12
            q += (left - 10 ** (i - 1)) * 10 ** j
        else
            q += (left - 10 ** (i - 1)) * 10 ** j
            q += right
        end
    end
    res -= q
end
if a.length - 2 >= 0
    if a[0].to_i > 2
        res -= 10 ** (a.length - 2)
    elsif a[0].to_i == 2
        res -= a[1, a.length - 2].to_i + 1
        res += 1 if a[a.length - 1].to_i < 2
    end
else
    if a[0].to_i >= 2
        res -= 1
    end
end
(lb - y).downto(0) do |i|
    j = lb - i - y
    q = 0
    mid = b[i, y].to_i
    left = b[0, i].to_i
    right = b[i + y, j].to_i
    if i == 0
        if mid < 12
            q += 10 ** j
        elsif mid == 12
            q += 10 ** j - right - 1
        end
    elsif i == lb - y
        q += 10 ** i - left
        q -= 1 if mid >= 12
    else
        if mid < 12
            q += (10 ** i - left) * 10 ** j
        elsif mid > 12
            q += (10 ** i - left - 1) * 10 ** j
        else
            q += (10 ** i - left - 1) * 10 ** j
            q += 10 ** j - right - 1
        end
    end
    res -= q
end
if b.length - 2 >= 0
    if b[0].to_i < 2
        res -= 10 ** (b.length - 2)
    elsif b[0].to_i == 2
        res -= 10 ** (b.length - 2) - b[1, b.length - 2].to_i
        res += 1 if b[b.length - 1].to_i >= 2
    end
end
puts res
0