結果
問題 | No.1810 RGB Biscuits |
ユーザー | MasKoaTS |
提出日時 | 2022-01-12 21:51:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 926 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 77,340 KB |
最終ジャッジ日時 | 2024-04-27 12:17:22 |
合計ジャッジ時間 | 3,122 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,684 KB |
testcase_01 | AC | 50 ms
62,160 KB |
testcase_02 | AC | 40 ms
53,152 KB |
testcase_03 | AC | 58 ms
67,728 KB |
testcase_04 | AC | 59 ms
68,396 KB |
testcase_05 | AC | 138 ms
77,088 KB |
testcase_06 | AC | 148 ms
76,984 KB |
testcase_07 | AC | 145 ms
77,268 KB |
testcase_08 | AC | 142 ms
77,340 KB |
testcase_09 | AC | 141 ms
77,124 KB |
testcase_10 | AC | 129 ms
76,464 KB |
testcase_11 | AC | 69 ms
72,920 KB |
testcase_12 | AC | 62 ms
71,008 KB |
testcase_13 | AC | 62 ms
71,532 KB |
testcase_14 | AC | 96 ms
76,344 KB |
testcase_15 | AC | 67 ms
73,804 KB |
testcase_16 | AC | 83 ms
76,956 KB |
testcase_17 | AC | 118 ms
76,972 KB |
testcase_18 | AC | 120 ms
76,740 KB |
testcase_19 | AC | 57 ms
66,356 KB |
testcase_20 | AC | 41 ms
53,612 KB |
testcase_21 | AC | 92 ms
76,408 KB |
ソースコード
mod = 10 ** 9 + 7 a,b = map(int,input().split()) n = int(input()) if not(1 <= a <= 10 ** 9 and 1 <= b <= 10 ** 9 and 1 <= n <= 1000): exit(1) t = [] for _ in range(n): t.append(int(input())) if not(0 <= t[-1] <= 10 ** 18): exit(1) def matrix_prod(A,B): res = [[0]*2 for _ in range(2)] for i in range(2): for j in range(2): for k in range(2): res[i][j] += A[i][k] * B[k][j] res[i][j] %= mod return res def matrix_exp(A,n): res = [[1,0],[0,1]] while(n): if(n & 1): res = matrix_prod(A,res) A = matrix_prod(A,A) n >>= 1 return res def P_convertion(A,v): res = [0]*2 for i in range(2): for j in range(2): res[i] += A[i][j] * v[j] res[i] %= mod return res A = [[a,b],[1,0]] v = [1,1] for i in t: d = i // 2 r = i % 2 v1 = P_convertion(matrix_exp(A,d),v) v2 = P_convertion(A,v1) if(r == 1): print((v1[0] + v1[1] + v2[0]) % mod) else: print((v1[0] + v1[1]) % mod)