結果

問題 No.1810 RGB Biscuits
ユーザー 👑 ygussanyygussany
提出日時 2021-12-29 14:35:44
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,620 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 33,152 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 20:02:07
合計ジャッジ時間 1,323 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define DIM 3
const int Mod = 1000000007;

void copy_matrix(int d, long long A[][DIM], long long B[][DIM])
{
	int i, j;
	for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = A[i][j];
}

void prod_matrix(int d, long long A[][DIM], long long B[][DIM], long long C[][DIM])
{
	int i, j, k;
	for (i = 0; i < d; i++) {
		for (j = 0; j < d; j++) {
			for (k = 0, C[i][j] = 0; k < d; k++) C[i][j] += A[i][k] * B[k][j] % Mod;
			C[i][j] %= Mod;
		}
	}
}

void pow_matrix(int d, long long A[][DIM], int k, long long B[][DIM])
{
	int i, j;
	long long C[2][DIM][DIM], D[DIM][DIM];
	copy_matrix(d, A, C[0]);
	for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = 0;
	for (i = 0; i < d; i++) B[i][i] = 1;
	for (i = 0, j = 1; k > 0; i ^= 1, j ^= 1, k >>= 1) {
		prod_matrix(d, C[i], C[i], C[j]);
		if (k % 2 == 1) {
			prod_matrix(d, B, C[i], D);
			copy_matrix(d, D, B);
		}
	}
}

void prod_matrix_vector(int d, long long A[][DIM], long long x[], long long y[])
{
	int i, j;
	for (i = 0; i < d; i++) {
		for (j = 0, y[i] = 0; j < d; j++) y[i] += A[i][j] * x[j] % Mod;
		y[i] %= Mod;
	}
}

int main()
{
	int i, A, B, N;
	long long T[1001];
	scanf("%d %d", &A, &B);
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &(T[i]));
	
	long long C[DIM][DIM] = {{A, B, 1}, {1, 0, 0}, {0, 0, 0}}, CC[DIM][DIM], x[DIM] = {1, 1, 0}, y[DIM];
	for (i = 1; i <= N; i++) {
		pow_matrix(3, C, T[i] / 2, CC);
		prod_matrix_vector(3, CC, x, y);
		if (T[i] % 2 == 0) printf("%lld\n", (y[0] + y[1] + y[2]) % Mod);
		else printf("%lld\n", (y[0] * (A + 1) + y[1] * (B + 1) + y[2]) % Mod);
	}
	fflush(stdout);
	return 0;
}
0