結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
![]() |
提出日時 | 2015-12-12 17:48:28 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 115 ms / 2,000 ms |
コード長 | 2,442 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-12-26 04:17:01 |
合計ジャッジ時間 | 5,636 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
コンパイルメッセージ
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
ソースコード
#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