結果

問題 No.434 占い
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-18 23:04:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 78,712 KB
最終ジャッジ日時 2023-08-14 14:52:18
合計ジャッジ時間 5,587 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,324 KB
testcase_01 AC 65 ms
71,048 KB
testcase_02 AC 65 ms
71,192 KB
testcase_03 AC 72 ms
71,120 KB
testcase_04 AC 73 ms
71,124 KB
testcase_05 AC 70 ms
71,188 KB
testcase_06 AC 94 ms
75,932 KB
testcase_07 AC 67 ms
71,312 KB
testcase_08 AC 82 ms
76,140 KB
testcase_09 AC 78 ms
76,216 KB
testcase_10 AC 80 ms
75,988 KB
testcase_11 AC 102 ms
77,408 KB
testcase_12 AC 105 ms
77,048 KB
testcase_13 AC 83 ms
76,296 KB
testcase_14 AC 83 ms
75,848 KB
testcase_15 AC 85 ms
77,016 KB
testcase_16 AC 83 ms
76,752 KB
testcase_17 AC 85 ms
76,576 KB
testcase_18 AC 101 ms
77,140 KB
testcase_19 AC 145 ms
77,924 KB
testcase_20 AC 255 ms
77,360 KB
testcase_21 AC 86 ms
76,960 KB
testcase_22 AC 87 ms
76,916 KB
testcase_23 AC 64 ms
71,368 KB
testcase_24 AC 91 ms
76,728 KB
testcase_25 AC 63 ms
71,144 KB
testcase_26 AC 90 ms
76,992 KB
testcase_27 AC 104 ms
76,720 KB
testcase_28 AC 131 ms
78,712 KB
testcase_29 AC 182 ms
78,604 KB
testcase_30 AC 264 ms
77,936 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 s in map(int, S[1:]):
        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 * s * 3 ** pow3
        num -= 1
    return (ans - 1) % 9 + 1

T = int(input())
for t in range(T):
    S = input()
    print(solve(S, inv))
0