結果
問題 | No.1172 Add Recursive Sequence |
ユーザー | Salmonize |
提出日時 | 2020-08-14 23:05:42 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,401 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 61,196 KB |
最終ジャッジ日時 | 2024-10-10 16:32:23 |
合計ジャッジ時間 | 11,947 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
38,272 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 29 ms
10,880 KB |
testcase_03 | AC | 30 ms
11,136 KB |
testcase_04 | AC | 30 ms
11,008 KB |
testcase_05 | AC | 30 ms
10,880 KB |
testcase_06 | AC | 68 ms
11,776 KB |
testcase_07 | AC | 40 ms
11,520 KB |
testcase_08 | AC | 41 ms
11,264 KB |
testcase_09 | AC | 46 ms
11,392 KB |
testcase_10 | AC | 463 ms
19,328 KB |
testcase_11 | AC | 461 ms
19,328 KB |
testcase_12 | AC | 178 ms
13,312 KB |
testcase_13 | AC | 168 ms
13,312 KB |
testcase_14 | AC | 3,022 ms
61,196 KB |
testcase_15 | AC | 938 ms
25,344 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
ソースコード
import sys readline = sys.stdin.buffer.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def Kitamasa(C, X, k, e0=0, e1=1, mod=10**9+7): ''' 0-indexed calc X[k] ''' n = len(X) def _plus1(g): ret = [(g[i-1] + g[-1] * C[i]) % mod for i in range(n)] ret[0] = g[-1] * C[0] % mod return ret def _mult2(g): ret = [e0]*(2 * n - 1) for i in range(n): for j in range(n): ret[i + j] = (ret[i + j] + g[i] * g[j]) % mod for i in range(2*n-2, n-1, -1): for j in range(n): ret[i + j - n] = (ret[i + j - n] + ret[i] * C[j]) % mod return ret[:n] g = [e0]*n g[0] = e1 t = k.bit_length() for i in range(t-1, -1, -1): g = _mult2(g) if k & (1<<i): g = _plus1(g) ans = e0 for i in range(n): ans = (ans + g[i] * X[i]) % mod return ans def solve(): k, n, m = nm() a = nl() c = nl()[::-1] f = [0]*n g = [list() for _ in range(n+1)] d = dict() mod = 10**9 + 7 for _ in range(m): l, r = nm() f[l] += 1 g[r].append(r-l) def plus1(g): ret = [(g[i-1] + g[-1] * c[i]) % mod for i in range(k)] ret[0] = g[-1] * c[0] % mod return ret def mult2(g): ret = [0]*(2 * k - 1) for i in range(k): for j in range(k): ret[i + j] = (ret[i + j] + g[i] * g[j]) % mod for i in range(2 * k - 2, k - 1, -1): for j in range(k): ret[i + j - k] = (ret[i + j - k] + ret[i] * c[j]) % mod return ret[:k] def search(x): if x in d: return d[x] if x < k: ret = [0] * k ret[x] = 1 d[x] = ret elif x & 1: d[x] = plus1(search(x-1)) else: d[x] = mult2(search(x>>1)) return d[x] cur = [0] * k for i in range(n): # print(i, f[i], g[i]) cur = plus1(cur) cur[0] += f[i] for x in g[i]: neg = search(x) for j in range(k): cur[j] -= neg[j] # print(cur, i, f[i], g[i]) print(sum(cur[j]*a[j] for j in range(k)) % mod) # cur = [1, 0] # for i in range(10): # cur = plus1(cur) # print(cur, search(i+1)) return solve()