結果

問題 No.434 占い
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-18 23:16:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 647 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 8,572 KB
最終ジャッジ日時 2023-08-14 14:54:38
合計ジャッジ時間 2,454 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,908 KB
testcase_01 AC 12 ms
7,876 KB
testcase_02 AC 12 ms
7,880 KB
testcase_03 AC 14 ms
7,884 KB
testcase_04 AC 15 ms
7,956 KB
testcase_05 AC 13 ms
7,852 KB
testcase_06 AC 14 ms
7,972 KB
testcase_07 AC 12 ms
7,956 KB
testcase_08 RE -
testcase_09 AC 16 ms
7,888 KB
testcase_10 AC 16 ms
7,944 KB
testcase_11 AC 17 ms
7,760 KB
testcase_12 AC 22 ms
8,536 KB
testcase_13 RE -
testcase_14 AC 15 ms
7,944 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 42 ms
7,944 KB
testcase_18 AC 45 ms
7,792 KB
testcase_19 AC 56 ms
8,572 KB
testcase_20 AC 100 ms
8,520 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 12 ms
7,880 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 51 ms
7,948 KB
testcase_28 AC 52 ms
8,284 KB
testcase_29 AC 67 ms
8,432 KB
testcase_30 AC 96 ms
8,284 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) - 1
    if lenS == 1:
        return ans
    if int(S) == 0:
        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, inv))
0