結果

問題 No.319 happy b1rthday 2 me
ユーザー char134217728
提出日時 2017-09-15 02:55:31
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-11-07 21:26:49
合計ジャッジ時間 4,708 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
ans = calc(b.chars.map &:to_i) - calc((a.to_i-1).to_s.chars.map &:to_i)
ans -= 1 if a[0] == 2 && a[-1] == 1
p ans
0