結果
問題 | No.757 チャンパーノウン定数 (2) |
ユーザー |
|
提出日時 | 2018-12-05 13:03:51 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 1,094 ms / 2,000 ms |
コード長 | 2,066 bytes |
コンパイル時間 | 39 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 69,888 KB |
最終ジャッジ日時 | 2024-07-18 13:21:34 |
合計ジャッジ時間 | 8,230 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
コンパイルメッセージ
Syntax OK
ソースコード
B = gets.to_iS = gets.chompL = S.sizeN = S.to_i(B)#N = gets.to_i(B)#N = 9**100000# guchoku# str = ((0..999).map{|e|e.to_s(B)}*"")# puts str[0..50]# puts str[N]def dig(y, w)# range "000".."999"i = y/wd = y%wi.to_s(B)[d] || "0"end# deprecateddef climb(x, sz, ofs, w)# range "100".."999"len = (sz-ofs)*w# p [x,sz,ofs,w]# p (ofs...sz).map{|e|e.to_s(B)}if x >= lenclimb(x-len, sz*B, sz, w+1)else# p B**(w-1)# ((ofs...sz).map{|e|e.to_s(B)}*"")[x]dig(x+B**(w-1)*w, w)endend# deprecateddef climb_flat(x, sz, ofs, w)len = (sz-ofs)*wwhile x >= lenx, sz, ofs, w = x-len, sz*B, sz, w+1len = (sz-ofs)*wenddig(x+B**(w-1)*w, w)end# deprecateddef climb_flat2(x)ofs, w = 1, 1len = (B-1)*w # ((B-1)*w)*B**wl = 0while x >= lenl += lenx, ofs, w = x-len, ofs*B, w+1len = ofs*(w*(B-1))enddig(x+len/(B-1), w)end# deprecateddef climb_flat3(x)lx = x# ofs, w = 1, 1# len = (B-1)*w # ((B-1)*w)*B**w# l = 0# i = 0# while x >= len# l += len# x, ofs, w = x-len, ofs*B, w+1# len = ofs*(w*(B-1))# #p [len, l]# #p [( ((B-1)*(i+1)+B-1).to_s(B)+"0"*(i+1) ).to_i(B), ( (i).to_s(B)+(B-2).to_s*(i)+(B-1).to_s ).to_i(B)]# i += 1# end# p [len, l]# p [x, len+l]# p [L, i]((L-10)..(L-1)).each do |w|len = ( ((B-1)*(w)+B-1).to_s(B)+"0"*(w) ).to_i(B)sum = ( (w-1).to_s(B)+(B-2).to_s*(w-1)+(B-1).to_s ).to_i(B)return dig(lx-sum+len/(B-1), w+1) if lx < len+sumendlen = ( ((B-1)*(L-1)+B-1).to_s(B)+"0"*(L-1) ).to_i(B)sum = ( (L-2).to_s(B)+(B-2).to_s*(L-2)+(B-1).to_s ).to_i(B)#p [len, sum]return dig(lx-sum+len/(B-1), L)endif N == 0p 0else#puts climb_flat(N-1, B, 1, 1)puts climb_flat2(N-1) if B <= 2 || L <= 20puts climb_flat3(N-1) unless B <= 2 || L <= 20end