結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー nanaenanae
提出日時 2018-12-05 00:23:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,374 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 13,128 KB
最終ジャッジ日時 2023-09-22 22:24:38
合計ジャッジ時間 5,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
12,628 KB
testcase_01 AC 17 ms
8,200 KB
testcase_02 AC 19 ms
8,236 KB
testcase_03 AC 17 ms
8,384 KB
testcase_04 AC 20 ms
8,380 KB
testcase_05 AC 21 ms
8,372 KB
testcase_06 AC 22 ms
8,312 KB
testcase_07 AC 17 ms
8,336 KB
testcase_08 AC 23 ms
8,376 KB
testcase_09 AC 23 ms
8,248 KB
testcase_10 AC 16 ms
8,276 KB
testcase_11 AC 18 ms
8,348 KB
testcase_12 AC 17 ms
8,180 KB
testcase_13 AC 22 ms
8,252 KB
testcase_14 AC 20 ms
8,236 KB
testcase_15 AC 21 ms
8,308 KB
testcase_16 AC 17 ms
8,428 KB
testcase_17 AC 23 ms
8,344 KB
testcase_18 AC 23 ms
8,256 KB
testcase_19 AC 16 ms
8,276 KB
testcase_20 AC 19 ms
8,344 KB
testcase_21 AC 18 ms
8,408 KB
testcase_22 AC 21 ms
8,448 KB
testcase_23 AC 21 ms
8,384 KB
testcase_24 AC 23 ms
8,320 KB
testcase_25 AC 18 ms
8,256 KB
testcase_26 AC 23 ms
8,248 KB
testcase_27 AC 23 ms
8,268 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    b = int(input())
    n = convert_base(b, input()) - 1


    # print(n)

    ok = 0
    ng = 10**5 + 1

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if get_length_d(b, mid) < n:
            ok = mid
        else:
            ng = mid

    # print('max_digit:', ok)
    # print('max_digit_length:', get_length_d(b, ok))

    dig = ok
    ok = b**dig - 1
    ng = b**(dig + 1)
    base = get_length_d(b, dig)
    bpdig = b**dig

    def get_remain_length(b, x):
        return (dig + 1) * (x - bpdig + 1)

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        tot = base + get_remain_length(b, mid)

        if tot <= n:
            ok = mid
        else:
            ng = mid

    t = base + get_remain_length(b, ok)

    # print(n)
    # print(t)

    s = reconvert(b, ok + 1)

    # print(s)

    print(s[n - t])


def get_length_d(b, d):
    return (d * b**(d+1) - (d+1) * b**d + 1) // (b - 1)

def convert_base(b, n):
    res = 0

    for ni in n:
        res = res*b + int(ni)

    return res

def reconvert(b, n):
    res = []

    while n > 0:
        res.append(str(n % b))
        n //= b

    res.reverse()

    return ''.join(res)

if __name__ == '__main__':
    assert convert_base(2, '1011') == 11
    assert reconvert(2, 7) == '111'
    assert reconvert(2, 6) == '110'
    main()
0