結果
問題 | No.1810 RGB Biscuits |
ユーザー | MasKoaTS |
提出日時 | 2024-11-30 19:02:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 359 ms / 2,000 ms |
コード長 | 2,080 bytes |
コンパイル時間 | 216 ms |
コンパイル使用メモリ | 82,192 KB |
実行使用メモリ | 79,084 KB |
最終ジャッジ日時 | 2024-11-30 19:02:32 |
合計ジャッジ時間 | 4,779 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,352 KB |
testcase_01 | AC | 64 ms
67,584 KB |
testcase_02 | AC | 58 ms
53,248 KB |
testcase_03 | AC | 91 ms
76,132 KB |
testcase_04 | AC | 97 ms
76,284 KB |
testcase_05 | AC | 300 ms
77,056 KB |
testcase_06 | AC | 306 ms
77,184 KB |
testcase_07 | AC | 359 ms
79,020 KB |
testcase_08 | AC | 292 ms
77,304 KB |
testcase_09 | AC | 348 ms
79,084 KB |
testcase_10 | AC | 225 ms
76,928 KB |
testcase_11 | AC | 111 ms
76,272 KB |
testcase_12 | AC | 99 ms
76,288 KB |
testcase_13 | AC | 108 ms
76,672 KB |
testcase_14 | AC | 155 ms
76,672 KB |
testcase_15 | AC | 111 ms
76,464 KB |
testcase_16 | AC | 128 ms
77,096 KB |
testcase_17 | AC | 206 ms
76,928 KB |
testcase_18 | AC | 197 ms
76,672 KB |
testcase_19 | AC | 76 ms
74,368 KB |
testcase_20 | AC | 43 ms
53,120 KB |
testcase_21 | AC | 134 ms
76,928 KB |
ソースコード
import sys input = sys.stdin.readline MOD = 10 ** 9 + 7 class Matrix: def __init__(self, A: list): if not(A and isinstance(A[0], list)): A = [A] self.A = A self.row = len(A) self.col = len(A[0]) self.I = None if(self.row == self.col): self.I = [[0] * self.col for _ in [0] * self.row] for i in range(self.row): self.I[i][i] = 1 def set_A(self, A: list) -> None: self.A = A def set_I(self, I) -> None: self.I = I def __str__(self): return str(self.A) __repr__ = __str__ def __add__(self, other): ret = Matrix(self) for i in range(self.row): for j in range(self.col): ret.A[i][j] = self.A[i][j] + other.A[i][j] ret.A[i][j] %= MOD return ret def __sub__(self, other): ret = Matrix(self) for i in range(self.row): for j in range(self.col): ret.A[i][j] = self.A[i][j] - other.A[i][j] ret.A[i][j] %= MOD return ret def __mul__(self, other): assert(self.col == other.row) ret = Matrix([[0]*other.col for _ in [0]*self.row]) for i in range(self.row): for j in range(other.col): ret.A[i][j] = sum(self.A[i][k] * other.A[k][j] % MOD for k in range(self.col)) ret.A[i][j] %= MOD return ret def __pow__(self, other: int): mat = self ret = Matrix(self.I) n = other while(n): if(n & 1): ret = mat * ret mat = mat * mat n >>= 1 return ret ''' Main Code ''' a, b = map(int, input().split()) A = Matrix([[a, b], [1, 0]]) v = Matrix([[1], [1]]) n = int(input()) for _ in [0] * n: t = int(input()) d = t // 2; r = t % 2 v1 = (A ** d) * v v2 = A * v1 ans = 0 if(r == 1): ans = (v1.A[0][0] + v1.A[1][0] + v2.A[0][0]) % MOD else: ans = (v1.A[0][0] + v1.A[1][0]) % MOD print(ans)