結果

問題 No.434 占い
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-18 23:13:07
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-08-14 14:53:52
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,768 KB
testcase_01 AC 14 ms
7,836 KB
testcase_02 AC 16 ms
7,772 KB
testcase_03 AC 16 ms
7,800 KB
testcase_04 AC 15 ms
7,820 KB
testcase_05 AC 15 ms
7,808 KB
testcase_06 AC 17 ms
7,880 KB
testcase_07 AC 15 ms
7,744 KB
testcase_08 AC 19 ms
7,884 KB
testcase_09 AC 19 ms
7,776 KB
testcase_10 AC 20 ms
7,796 KB
testcase_11 AC 20 ms
7,812 KB
testcase_12 AC 26 ms
8,528 KB
testcase_13 AC 19 ms
7,828 KB
testcase_14 AC 20 ms
7,880 KB
testcase_15 AC 51 ms
8,352 KB
testcase_16 AC 52 ms
8,120 KB
testcase_17 AC 49 ms
7,828 KB
testcase_18 AC 52 ms
7,948 KB
testcase_19 AC 64 ms
8,360 KB
testcase_20 AC 113 ms
8,408 KB
testcase_21 AC 52 ms
8,336 KB
testcase_22 AC 54 ms
8,300 KB
testcase_23 AC 15 ms
7,776 KB
testcase_24 AC 48 ms
8,224 KB
testcase_25 AC 15 ms
8,280 KB
testcase_26 AC 35 ms
8,308 KB
testcase_27 AC 58 ms
7,816 KB
testcase_28 AC 59 ms
8,336 KB
testcase_29 AC 76 ms
8,428 KB
testcase_30 AC 108 ms
8,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

inv = [0, 1, 5, 0, 7, 2, 0, 4, 8, 0]

def solve(S, inv):
    pow3 = 0
    cum = 1
    ans = int(S[0])
    lenS = len(S)
    if lenS == 1:
        return ans
    if S == '0' * lenS:
        return 0
    num = lenS - 1
    for i in range(1, lenS):
        n = num
        d = lenS - n
        while not n % 3:
            pow3 += 1
            n //= 3
        while not d % 3:
            pow3 -= 1
            d //= 3
        cum = (cum * n * inv[d % 9]) % 9
        if pow3 < 2:
            ans += cum * int(S[i]) * 3 ** pow3
        num -= 1
    return (ans - 1) % 9 + 1

T = int(input())
for S in sys.stdin:
    print(solve(S.rstrip(), inv))
0