結果

問題 No.1847 Good Sequence
ユーザー 👑 ygussanyygussany
提出日時 2022-02-18 23:24:32
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 58 ms / 3,000 ms
コード長 1,701 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 30,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 20:08:48
合計ジャッジ時間 2,879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 56 ms
4,376 KB
testcase_02 AC 28 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 13 ms
4,384 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 13 ms
4,376 KB
testcase_20 AC 54 ms
4,376 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 58 ms
4,380 KB
testcase_23 AC 49 ms
4,380 KB
testcase_24 AC 54 ms
4,384 KB
testcase_25 AC 54 ms
4,380 KB
testcase_26 AC 54 ms
4,380 KB
testcase_27 AC 54 ms
4,376 KB
testcase_28 AC 55 ms
4,380 KB
testcase_29 AC 53 ms
4,376 KB
testcase_30 AC 55 ms
4,380 KB
testcase_31 AC 57 ms
4,380 KB
testcase_32 AC 53 ms
4,380 KB
testcase_33 AC 54 ms
4,380 KB
testcase_34 AC 57 ms
4,376 KB
testcase_35 AC 54 ms
4,376 KB
testcase_36 AC 57 ms
4,380 KB
testcase_37 AC 55 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 52 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define DIM 70
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], long long 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);
		}
	}
}

int main()
{
	long long L;
	int i, N, M, K, flag[11] = {};
	scanf("%lld %d %d", &L, &N, &M);
	for (i = 1; i <= M; i++) {
		scanf("%d", &K);
		flag[K] = 1;
	}
	
	int j, k, ii, jj;
	long long A[DIM][DIM] = {}, B[DIM][DIM];
	for (i = 1, j = 1; j <= N; j++, i += j) A[i][0] = 1;
	for (i = 1, j = 1, k = 1; 1; i++, k++) {
		if (k > j + 1) {
			j++;
			k = 1;
			if (j > N) break;
		}
		if (k != j || flag[j] == 0) { 
			for (ii = 1, jj = 1; jj <= N; jj++, ii += jj) if (jj != j) A[ii][i] = 1;
		} else A[DIM-1][i] = N - 1;
		if (k <= j) A[i+1][i] = 1;
		else A[i][i] = 1;
	}
	A[DIM-1][DIM-1] = N;
	
	long long ans = 0;
	pow_matrix(DIM, A, L, B);
	for (i = 1, j = 1, ans = B[DIM-1][0]; j <= N; j++, i += j + 1) if (flag[j] != 0) ans += B[i][0];
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0