結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,768 KB
testcase_01 AC 16 ms
7,760 KB
testcase_02 AC 15 ms
7,716 KB
testcase_03 AC 15 ms
7,772 KB
testcase_04 AC 15 ms
7,776 KB
testcase_05 AC 15 ms
7,900 KB
testcase_06 AC 17 ms
7,896 KB
testcase_07 AC 16 ms
7,956 KB
testcase_08 RE -
testcase_09 AC 18 ms
7,780 KB
testcase_10 AC 19 ms
7,712 KB
testcase_11 AC 20 ms
7,856 KB
testcase_12 AC 26 ms
8,572 KB
testcase_13 RE -
testcase_14 AC 19 ms
7,772 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 49 ms
7,884 KB
testcase_18 AC 51 ms
7,884 KB
testcase_19 AC 62 ms
8,404 KB
testcase_20 AC 119 ms
8,416 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 15 ms
7,932 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 53 ms
7,840 KB
testcase_28 AC 54 ms
8,172 KB
testcase_29 AC 70 ms
8,500 KB
testcase_30 AC 111 ms
8,372 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):
        return 0
    num = lenS - 1
    for s in 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 * (ord(s) - 48) * 3 ** pow3
        num -= 1
    return (ans - 1) % 9 + 1

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