結果
| 問題 |
No.434 占い
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-18 23:18:27 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 668 bytes |
| コンパイル時間 | 106 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-11-22 13:02:06 |
| 合計ジャッジ時間 | 2,579 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 RE * 9 |
ソースコード
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))