結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー maimai
提出日時 2018-12-05 11:22:46
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,007 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 133,440 KB
最終ジャッジ日時 2023-09-25 14:07:15
合計ジャッジ時間 21,233 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,300 KB
testcase_01 AC 80 ms
15,304 KB
testcase_02 AC 80 ms
15,148 KB
testcase_03 AC 79 ms
15,120 KB
testcase_04 AC 80 ms
15,224 KB
testcase_05 AC 78 ms
15,364 KB
testcase_06 AC 79 ms
15,296 KB
testcase_07 AC 78 ms
15,144 KB
testcase_08 AC 78 ms
15,084 KB
testcase_09 AC 80 ms
15,144 KB
testcase_10 AC 79 ms
15,156 KB
testcase_11 AC 79 ms
15,304 KB
testcase_12 AC 79 ms
15,264 KB
testcase_13 AC 80 ms
15,296 KB
testcase_14 AC 78 ms
15,088 KB
testcase_15 AC 79 ms
15,364 KB
testcase_16 AC 80 ms
15,244 KB
testcase_17 AC 80 ms
15,260 KB
testcase_18 AC 80 ms
15,112 KB
testcase_19 AC 80 ms
15,280 KB
testcase_20 AC 81 ms
15,300 KB
testcase_21 AC 81 ms
15,360 KB
testcase_22 AC 80 ms
15,164 KB
testcase_23 AC 79 ms
15,124 KB
testcase_24 AC 80 ms
15,284 KB
testcase_25 AC 81 ms
15,120 KB
testcase_26 AC 81 ms
15,120 KB
testcase_27 AC 82 ms
15,084 KB
testcase_28 TLE -
testcase_29 AC 1,609 ms
133,440 KB
testcase_30 AC 93 ms
22,908 KB
testcase_31 AC 126 ms
36,296 KB
testcase_32 AC 82 ms
15,600 KB
testcase_33 AC 157 ms
36,632 KB
testcase_34 AC 589 ms
114,692 KB
testcase_35 AC 114 ms
32,156 KB
testcase_36 AC 99 ms
25,604 KB
testcase_37 AC 1,315 ms
122,844 KB
testcase_38 AC 1,781 ms
126,660 KB
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 AC 985 ms
96,028 KB
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 AC 1,697 ms
112,476 KB
testcase_47 TLE -
testcase_48 AC 1,660 ms
112,072 KB
testcase_49 TLE -
testcase_50 AC 81 ms
15,416 KB
testcase_51 AC 85 ms
15,092 KB
testcase_52 AC 84 ms
15,408 KB
testcase_53 AC 82 ms
15,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:43: warning: assigned but unused variable - sz
Main.rb:45: warning: assigned but unused variable - l
Syntax OK

ソースコード

diff #

B = gets.to_i
N = gets.to_i(B)

# guchoku
# str = ((0..999).map{|e|e.to_s(B)}*"")
# puts str[0..50]
# puts str[N]

def dig(y, sz, w)
    # range "000".."999"
    i = y/w
    d = y%w
    i.to_s(B)[d] || "0"
end

# deprecated
def 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 >= len
        climb(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, sz, w)
    end
end


def climb_flat(x, sz, ofs, w)
    len = (sz-ofs)*w
    while x >= len
        x, sz, ofs, w = x-len, sz*B, sz, w+1
        len = (sz-ofs)*w
    end
    dig(x+B**(w-1)*w, sz, w)
end

def climb_flat2(x)
    sz, ofs, w = B, 1, 1
    len = (B-1)*w
    l = len
    while x >= len
        x, ofs, w = x-len, ofs*B, w+1
        len = ofs*(w*(B-1))
    end
    dig(x+len/(B-1), ofs*B, w)
end


if N == 0
    p 0
else
    # puts climb_flat(N-1, B, 1, 1)
    puts climb_flat2(N-1)
end


0