結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー nanaenanae
提出日時 2018-12-05 00:07:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,330 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 12,992 KB
最終ジャッジ日時 2023-09-22 21:31:18
合計ジャッジ時間 5,223 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
12,936 KB
testcase_01 AC 16 ms
8,248 KB
testcase_02 WA -
testcase_03 AC 16 ms
8,284 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 22 ms
8,352 KB
testcase_09 AC 22 ms
8,212 KB
testcase_10 AC 16 ms
8,320 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 21 ms
8,376 KB
testcase_25 AC 17 ms
8,408 KB
testcase_26 WA -
testcase_27 WA -
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)

    def get_remain_length(b, x):
        return (dig + 1) * (x - b**dig + 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
    n = n[::-1]

    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 reconvert(2, 7) == '111'
    assert reconvert(2, 6) == '110'
    main()
0