結果
問題 | No.1299 Random Array Score |
ユーザー | Coki628 |
提出日時 | 2020-11-27 23:08:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 2,231 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 82,588 KB |
実行使用メモリ | 102,332 KB |
最終ジャッジ日時 | 2024-07-26 19:29:08 |
合計ジャッジ時間 | 4,435 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,500 KB |
testcase_01 | AC | 39 ms
53,568 KB |
testcase_02 | AC | 39 ms
53,864 KB |
testcase_03 | AC | 91 ms
102,332 KB |
testcase_04 | AC | 92 ms
101,756 KB |
testcase_05 | AC | 77 ms
99,024 KB |
testcase_06 | AC | 72 ms
94,728 KB |
testcase_07 | AC | 73 ms
94,300 KB |
testcase_08 | AC | 91 ms
101,728 KB |
testcase_09 | AC | 44 ms
61,576 KB |
testcase_10 | AC | 60 ms
79,224 KB |
testcase_11 | AC | 46 ms
65,172 KB |
testcase_12 | AC | 70 ms
90,464 KB |
testcase_13 | AC | 89 ms
101,528 KB |
testcase_14 | AC | 72 ms
91,212 KB |
testcase_15 | AC | 73 ms
93,900 KB |
testcase_16 | AC | 73 ms
94,320 KB |
testcase_17 | AC | 48 ms
67,072 KB |
testcase_18 | AC | 63 ms
81,472 KB |
testcase_19 | AC | 65 ms
84,392 KB |
testcase_20 | AC | 54 ms
72,776 KB |
testcase_21 | AC | 43 ms
61,532 KB |
testcase_22 | AC | 49 ms
67,700 KB |
testcase_23 | AC | 72 ms
93,164 KB |
testcase_24 | AC | 77 ms
97,500 KB |
testcase_25 | AC | 71 ms
92,324 KB |
testcase_26 | AC | 44 ms
60,420 KB |
testcase_27 | AC | 50 ms
68,692 KB |
testcase_28 | AC | 48 ms
65,456 KB |
testcase_29 | AC | 52 ms
70,684 KB |
testcase_30 | AC | 70 ms
89,888 KB |
testcase_31 | AC | 53 ms
70,408 KB |
testcase_32 | AC | 91 ms
101,560 KB |
testcase_33 | AC | 95 ms
100,336 KB |
testcase_34 | AC | 75 ms
98,044 KB |
testcase_35 | AC | 93 ms
100,324 KB |
testcase_36 | AC | 74 ms
97,272 KB |
ソースコード
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF = 10**19 MOD = 998244353 EPS = 10**-10 def div(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def mat_pow(mat, init, K, MOD): """ 行列累乗 """ def mat_dot(A, B, MOD): """ 行列の積 """ if not isinstance(A[0], list) and not isinstance(A[0], tuple): A = [A] if not isinstance(B[0], list) and not isinstance(A[0], tuple): B = [[b] for b in B] n1 = len(A) n2 = len(A[0]) _ = len(B) m2 = len(B[0]) res = list2d(n1, m2, 0) for i in range(n1): for j in range(m2): for k in range(n2): res[i][j] += A[i][k] * B[k][j] res[i][j] %= MOD return res def _mat_pow(mat, k, MOD): """ 行列matをk乗する """ n = len(mat) res = list2d(n, n, 0) for i in range(n): res[i][i] = 1 while k > 0: if k & 1: res = mat_dot(res, mat, MOD) mat = mat_dot(mat, mat, MOD) k >>= 1 return res res = _mat_pow(mat, K, MOD) res = mat_dot(res, init, MOD) return [a[0] for a in res] N, K = MAP() A = LIST() # dp0 = [0] * (K+1) # dp1 = [0] * (K+1) # dp0[0] = sum(A) % MOD # dp1[0] = div(sum(A), N, MOD) # for i in range(K): # dp0[i+1] = dp0[i] + dp1[i]*N # dp0[i+1] %= MOD # dp1[i+1] = (dp0[i] + dp1[i]*N) / N # dp1[i+1] %= MOD # ans = dp0[K] # print(ans) invN = div(1, N, MOD) mat = [ [1, N], [invN, 1], ] init = [sum(A) % MOD, div(sum(A), N, MOD)] res = mat_pow(mat, init, K, MOD) print(res[0])