結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー maimai
提出日時 2018-12-05 11:22:26
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,022 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 132,384 KB
最終ジャッジ日時 2023-09-25 14:13:43
合計ジャッジ時間 64,517 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 AC 1,129 ms
112,056 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 TLE -
testcase_20 AC 1,651 ms
111,948 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 980 ms
111,868 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 TLE -
testcase_43 WA -
testcase_44 AC 890 ms
119,056 KB
testcase_45 WA -
testcase_46 AC 1,112 ms
112,236 KB
testcase_47 WA -
testcase_48 AC 1,614 ms
111,976 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:44: warning: assigned but unused variable - sz
Main.rb:46: warning: assigned but unused variable - l
Syntax OK

ソースコード

diff #

B = gets.to_i
#N = gets.to_i(B)
N = 3**100000

# 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