結果
問題 | No.434 占い |
ユーザー | rlangevin |
提出日時 | 2023-10-17 22:23:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 973 ms / 2,000 ms |
コード長 | 1,831 bytes |
コンパイル時間 | 291 ms |
コンパイル使用メモリ | 81,636 KB |
実行使用メモリ | 87,360 KB |
最終ジャッジ日時 | 2023-10-17 22:24:02 |
合計ジャッジ時間 | 10,069 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,728 KB |
testcase_01 | AC | 40 ms
55,504 KB |
testcase_02 | AC | 40 ms
55,564 KB |
testcase_03 | AC | 46 ms
61,744 KB |
testcase_04 | AC | 48 ms
61,892 KB |
testcase_05 | AC | 46 ms
61,744 KB |
testcase_06 | AC | 54 ms
65,776 KB |
testcase_07 | AC | 78 ms
74,848 KB |
testcase_08 | AC | 147 ms
78,976 KB |
testcase_09 | AC | 184 ms
79,592 KB |
testcase_10 | AC | 143 ms
78,584 KB |
testcase_11 | AC | 174 ms
79,760 KB |
testcase_12 | AC | 75 ms
77,796 KB |
testcase_13 | AC | 151 ms
80,000 KB |
testcase_14 | AC | 170 ms
80,924 KB |
testcase_15 | AC | 956 ms
86,088 KB |
testcase_16 | AC | 550 ms
80,956 KB |
testcase_17 | AC | 431 ms
80,124 KB |
testcase_18 | AC | 323 ms
79,120 KB |
testcase_19 | AC | 287 ms
80,272 KB |
testcase_20 | AC | 117 ms
78,712 KB |
testcase_21 | AC | 973 ms
86,088 KB |
testcase_22 | AC | 574 ms
82,208 KB |
testcase_23 | AC | 47 ms
61,744 KB |
testcase_24 | AC | 515 ms
80,792 KB |
testcase_25 | AC | 53 ms
73,216 KB |
testcase_26 | AC | 400 ms
81,084 KB |
testcase_27 | AC | 406 ms
79,736 KB |
testcase_28 | AC | 406 ms
80,120 KB |
testcase_29 | AC | 466 ms
82,072 KB |
testcase_30 | AC | 471 ms
87,360 KB |
ソースコード
import sys input = sys.stdin.readline class SegmentTree: def __init__(self, size, f=lambda x, y : x * y % 9, default=1): self.size = 2**(size-1).bit_length() self.default = default self.dat = [default]*(self.size*2) self.f = f def update(self, i, x): i += self.size self.dat[i] = x while i > 0: i >>= 1 self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1]) def query(self, l, r): l += self.size r += self.size lres, rres = self.default, self.default while l < r: if l & 1: lres = self.f(lres, self.dat[l]) l += 1 if r & 1: r -= 1 rres = self.f(self.dat[r], rres) l >>= 1 r >>= 1 res = self.f(lres, rres) return res def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) return arr Q = int(input().rstrip()) T = SegmentTree(10**5+5) for _ in range(Q): S = list(input().rstrip()) S = list(map(int, S)) if len(set(S)) == 1 and S[0] == 0: print(0) continue N = len(S) - 1 L = [0] * (N + 1) ans = S[0] for i in range(1, N + 1): SS = set() for t in factorization(N - i + 1): SS.add(t[0]) L[t[0]] += t[1] for t in factorization(i): SS.add(t[0]) L[t[0]] -= t[1] for s in SS: T.update(s, pow(s, L[s], 9)) ans += T.query(0, N + 1) * S[i] ans %= 9 print(ans) if ans else print(9)