結果

問題 No.313 π
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-07 23:05:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 1,143 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 18,348 KB
最終ジャッジ日時 2023-10-12 20:11:00
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
18,296 KB
testcase_01 AC 107 ms
18,208 KB
testcase_02 AC 106 ms
18,328 KB
testcase_03 AC 107 ms
18,340 KB
testcase_04 AC 107 ms
18,196 KB
testcase_05 AC 108 ms
18,196 KB
testcase_06 AC 107 ms
18,200 KB
testcase_07 AC 108 ms
18,336 KB
testcase_08 AC 107 ms
18,252 KB
testcase_09 AC 107 ms
18,156 KB
testcase_10 AC 106 ms
18,296 KB
testcase_11 AC 108 ms
18,328 KB
testcase_12 AC 107 ms
18,212 KB
testcase_13 AC 107 ms
18,236 KB
testcase_14 AC 108 ms
18,212 KB
testcase_15 AC 107 ms
18,200 KB
testcase_16 AC 107 ms
18,192 KB
testcase_17 AC 106 ms
18,296 KB
testcase_18 AC 106 ms
18,196 KB
testcase_19 AC 107 ms
18,344 KB
testcase_20 AC 109 ms
18,196 KB
testcase_21 AC 107 ms
18,200 KB
testcase_22 AC 106 ms
18,208 KB
testcase_23 AC 106 ms
18,196 KB
testcase_24 AC 107 ms
18,328 KB
testcase_25 AC 107 ms
18,244 KB
testcase_26 AC 106 ms
18,328 KB
testcase_27 AC 108 ms
18,348 KB
testcase_28 AC 108 ms
18,248 KB
testcase_29 AC 107 ms
18,324 KB
testcase_30 AC 107 ms
18,276 KB
testcase_31 AC 107 ms
18,156 KB
testcase_32 AC 107 ms
18,332 KB
testcase_33 AC 107 ms
18,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def compress(ps):
    ps, depth = adjust_to_pow2(ps)
    t = build_segtree(ps)
    return [calc_partial_sum(t, d) % 10 for d in range(depth + 1)]


def adjust_to_pow2(ps):
    n = len(ps)
    depth = len(bin(n - 1)) - 2
    adjusted_length = 1 << depth
    return ps + [0] * (adjusted_length - n), depth


def build_segtree(ps):
    n = len(ps)
    segtree = [0] * n + ps
    for i in range(n - 1, 0, -1):
        segtree[i] = segtree[i << 1] + segtree[(i << 1) | 1]
    return segtree

def calc_partial_sum(t, d):
    return sum(t[i] for i in range(1 << d, 2 << d, 2))


def detect_dif(correct, wrong):
    dif = correct[0] - wrong[0]
    idx = 0
    depth = len(correct) - 1
    for c, w in zip(correct[1:], wrong[1:]):
        depth -= 1
        if c == w:
            idx += 1 << depth
    return idx, dif


def solve(qs, correct):
    wrong = compress(qs)
    idx, dif = detect_dif(correct, wrong)
    return qs[idx], (qs[idx] + dif) % 10

if __name__ == '__main__':
    correct = [7, 9, 1, 9, 6, 8, 1, 5, 9, 8, 1, 4, 9, 4, 1, 1, 6, 1, 1]
    qi = input()
    qi = qi[0] + qi[2:]
    qs = list(map(int, qi))
    print(*solve(qs, correct))
0