結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,796 KB
testcase_01 AC 15 ms
7,948 KB
testcase_02 AC 15 ms
7,800 KB
testcase_03 AC 16 ms
7,816 KB
testcase_04 AC 16 ms
7,840 KB
testcase_05 AC 17 ms
7,804 KB
testcase_06 AC 20 ms
7,808 KB
testcase_07 AC 16 ms
7,808 KB
testcase_08 AC 19 ms
7,816 KB
testcase_09 AC 19 ms
7,904 KB
testcase_10 AC 19 ms
7,808 KB
testcase_11 AC 25 ms
7,832 KB
testcase_12 AC 64 ms
7,748 KB
testcase_13 AC 18 ms
7,804 KB
testcase_14 AC 19 ms
7,880 KB
testcase_15 AC 50 ms
8,484 KB
testcase_16 AC 51 ms
8,212 KB
testcase_17 AC 48 ms
7,880 KB
testcase_18 AC 58 ms
8,004 KB
testcase_19 AC 107 ms
8,008 KB
testcase_20 AC 503 ms
7,800 KB
testcase_21 AC 51 ms
8,372 KB
testcase_22 AC 54 ms
8,196 KB
testcase_23 AC 15 ms
7,952 KB
testcase_24 AC 46 ms
8,260 KB
testcase_25 AC 15 ms
8,328 KB
testcase_26 AC 33 ms
8,252 KB
testcase_27 AC 61 ms
7,948 KB
testcase_28 AC 65 ms
7,880 KB
testcase_29 AC 132 ms
7,880 KB
testcase_30 AC 414 ms
7,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 t in range(T):
    S = input()
    print(solve(S, inv))
0