結果

問題 No.319 happy b1rthday 2 me
ユーザー char134217728char134217728
提出日時 2017-09-15 02:55:31
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-25 10:47:03
合計ジャッジ時間 4,816 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 91 ms
12,032 KB
testcase_02 AC 93 ms
12,288 KB
testcase_03 AC 92 ms
12,288 KB
testcase_04 AC 91 ms
12,160 KB
testcase_05 AC 89 ms
12,288 KB
testcase_06 AC 90 ms
12,288 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 91 ms
12,416 KB
testcase_10 AC 91 ms
12,160 KB
testcase_11 WA -
testcase_12 AC 91 ms
12,288 KB
testcase_13 AC 92 ms
12,160 KB
testcase_14 AC 91 ms
12,160 KB
testcase_15 AC 94 ms
12,288 KB
testcase_16 AC 98 ms
12,288 KB
testcase_17 WA -
testcase_18 AC 95 ms
12,160 KB
testcase_19 AC 96 ms
12,160 KB
testcase_20 AC 94 ms
12,160 KB
testcase_21 AC 97 ms
12,288 KB
testcase_22 AC 97 ms
12,160 KB
testcase_23 WA -
testcase_24 AC 96 ms
12,288 KB
testcase_25 AC 95 ms
12,288 KB
testcase_26 AC 94 ms
12,160 KB
testcase_27 WA -
testcase_28 AC 93 ms
12,160 KB
testcase_29 AC 93 ms
12,160 KB
testcase_30 AC 94 ms
12,160 KB
testcase_31 AC 94 ms
12,160 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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