結果
| 問題 | 
                            No.1810 RGB Biscuits
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-11-08 17:47:17 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,349 bytes | 
| コンパイル時間 | 772 ms | 
| コンパイル使用メモリ | 56,740 KB | 
| 最終ジャッジ日時 | 2025-01-25 14:49:04 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge8 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 TLE * 1 | 
| other | AC * 1 WA * 3 TLE * 16 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |         int A, B, N; scanf("%d%d%d", &A, &B, &N);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:53:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |                 i64 T; scanf("%lld", &T);
      |                        ~~~~~^~~~~~~~~~~~
            
            ソースコード
/*
	WA: Overflow
*/
#include <stdio.h>
#include <vector>
constexpr int MOD = 1'000'000'007;
struct matrix_t {
	using i64 = int;
	std::vector<std::vector<i64>> matrix;
	matrix_t(): matrix(3, std::vector<i64>(3)) {}
	matrix_t(const std::vector<std::vector<i64>>& matrix): matrix(matrix) {}
	static matrix_t E() {
		return matrix_t({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}});
	}
	std::vector<i64>& operator[](int k) { return matrix[k]; }
	inline matrix_t operator*(const matrix_t& r) const {
		matrix_t ret;
		for(size_t i = 0; i < 3; i++) {
			for(size_t j = 0; j < 3; j++) {
				for(size_t k = 0; k < 3; k++) {
					(ret[i][j] += matrix[i][k] * r.matrix[k][j]) %= MOD;
				}
			}
		}
		return std::move(ret);
	}
	inline matrix_t operator^=(i64 k) {
		matrix_t tmp = E();
		while(k) {
			if(k & 1) tmp = tmp * (*this);
			(*this) = (*this) * (*this);
			k >>= 1;
		}
		matrix.swap(tmp.matrix);
		return *this;
	}
};
int main() {
	int A, B, N; scanf("%d%d%d", &A, &B, &N);
	using i64 = long long;
	while(N--) {
		i64 T; scanf("%lld", &T);
		matrix_t matrix({{A, B, 1}, {1, 0, 0}, {0, 0, 0}});
		matrix ^= T / 2;
		if(T % 2) {
			matrix = matrix_t({{1, 0, 0}, {0, 1, 0}, {A, B, 1}}) * matrix;
		}
		int ans = 0;
		for(size_t i = 0; i < 3; i++) for(size_t j = 0; j < 2; j++) ans = (ans + matrix[i][j]) % MOD;
		printf("%d\n", ans);
	}
	return 0;
}