結果

問題 No.434 占い
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-18 23:18:27
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 668 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2023-08-14 14:54:49
合計ジャッジ時間 2,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,828 KB
testcase_01 AC 15 ms
7,776 KB
testcase_02 AC 15 ms
7,800 KB
testcase_03 AC 16 ms
7,772 KB
testcase_04 AC 16 ms
7,928 KB
testcase_05 AC 15 ms
7,936 KB
testcase_06 AC 17 ms
7,880 KB
testcase_07 AC 16 ms
7,876 KB
testcase_08 RE -
testcase_09 AC 19 ms
7,876 KB
testcase_10 AC 19 ms
7,832 KB
testcase_11 AC 21 ms
7,772 KB
testcase_12 AC 26 ms
8,344 KB
testcase_13 RE -
testcase_14 AC 20 ms
7,916 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 51 ms
7,780 KB
testcase_18 AC 55 ms
7,896 KB
testcase_19 AC 67 ms
8,608 KB
testcase_20 AC 121 ms
8,412 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 16 ms
7,776 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 60 ms
7,776 KB
testcase_28 AC 62 ms
8,248 KB
testcase_29 AC 81 ms
8,444 KB
testcase_30 AC 115 ms
8,312 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 not int(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