結果

問題 No.319 happy b1rthday 2 me
ユーザー char134217728char134217728
提出日時 2017-09-15 03:00:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-25 10:50:04
合計ジャッジ時間 4,158 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,160 KB
testcase_01 AC 76 ms
12,032 KB
testcase_02 AC 83 ms
12,288 KB
testcase_03 AC 77 ms
12,160 KB
testcase_04 AC 82 ms
12,288 KB
testcase_05 AC 79 ms
12,288 KB
testcase_06 AC 81 ms
12,288 KB
testcase_07 AC 77 ms
12,160 KB
testcase_08 AC 75 ms
12,032 KB
testcase_09 AC 79 ms
12,160 KB
testcase_10 AC 76 ms
12,288 KB
testcase_11 AC 77 ms
12,288 KB
testcase_12 AC 81 ms
12,160 KB
testcase_13 AC 77 ms
12,160 KB
testcase_14 AC 77 ms
12,288 KB
testcase_15 AC 77 ms
12,160 KB
testcase_16 AC 77 ms
12,288 KB
testcase_17 AC 79 ms
12,288 KB
testcase_18 AC 77 ms
12,032 KB
testcase_19 AC 78 ms
12,032 KB
testcase_20 AC 76 ms
12,160 KB
testcase_21 AC 77 ms
12,160 KB
testcase_22 AC 79 ms
12,288 KB
testcase_23 AC 77 ms
12,160 KB
testcase_24 AC 81 ms
12,160 KB
testcase_25 AC 82 ms
12,032 KB
testcase_26 AC 80 ms
12,288 KB
testcase_27 AC 78 ms
12,160 KB
testcase_28 AC 77 ms
12,160 KB
testcase_29 AC 79 ms
12,160 KB
testcase_30 AC 77 ms
12,288 KB
testcase_31 AC 80 ms
12,416 KB
testcase_32 AC 77 ms
12,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a, b = gets.chomp.split(" ")
def pow(n)
  n.times.inject(1){|a,b|a *= 10}
end
def calc(a)
  l = a.length
  if l == 1
    return a[0] > 1 ? 1 : 0
  end
  ret = 1
  (0..l-2).each do |i|
    ret += a[0...i].join.to_i * pow(l-i-2)
    case a[i..i+1].join.to_i <=> 12
    when -1
      #
    when 0
      ret += [a[i+2...l].join.to_i+1, 1].max
    when 1
      ret += pow(l-i-2)
    else
    end

    if i > 0
      ret += pow(l-i-2);
    else
      case a[0] <=> 2
      when -1
        #
      when 0
        ret += a[1..l-2].join.to_i
        ret += 1 if a[l-1] >= 2
      when 1
        ret += pow(l-2)
      else
      end
    end
  end
  ret
end
a = (a.to_i - 1).to_s.chars.map &:to_i
ans = calc(b.chars.map &:to_i) - calc(a)
ans -= 1 if a[-1] == 1 && (a.length == 1 || a[0] == 2)
p ans
0