結果

問題 No.1759 Silver Tour
ユーザー 👑 ygussanyygussany
提出日時 2021-11-20 15:22:55
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,622 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 30,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 09:52:04
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 0 ms
4,380 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 0 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 0 ms
4,376 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 0 ms
4,376 KB
testcase_24 AC 0 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 0 ms
4,376 KB
testcase_29 AC 0 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 0 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 0 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 0 ms
4,376 KB
testcase_37 AC 0 ms
4,376 KB
testcase_38 AC 0 ms
4,380 KB
testcase_39 AC 0 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 0 ms
4,380 KB
testcase_42 AC 0 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int Mod;

void DFS(int W, int i, int j, int l, int flag[][51], int adj[])
{
	if (l == W * 2) {
		adj[j]++;
		return;
	}
	flag[i][j] = 1;
	if (i == 0) {
		if (j > 1 && flag[i+1][j-1] == 0) DFS(W, i + 1, j - 1, l + 1, flag, adj);
		if (flag[i+1][j] == 0) DFS(W, i + 1, j, l + 1, flag, adj);
		if (j < W && flag[i+1][j+1] == 0) DFS(W, i + 1, j + 1, l + 1, flag, adj);
	} else {
		if (j > 1 && flag[i-1][j-1] == 0) DFS(W, i - 1, j - 1, l + 1, flag, adj);
		if (j < W && flag[i-1][j+1] == 0) DFS(W, i - 1, j + 1, l + 1, flag, adj);
	}
	flag[i][j] = 0;
}

int main()
{
	int H, W, Mod;
	scanf("%d %d %d", &H, &W, &Mod);
	if (W == 1) {
		printf("1\n");
		fflush(stdout);
		return 0;
	} else if (H % 2 != 0) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}
	
	int i, j, k;
	long long dp[2][52] = {}, tmp;
	for (j = 1; j <= W; j++) dp[0][j] = 1;
	for (i = 1; i <= H / 2; i++) {
		for (j = 1; j <= W; j++) {
			tmp = dp[0][j] % Mod;
			dp[0][j] = 0;
			if (tmp == 0) continue;
			if (W % 2 == 0) {
				if (j % 2 != 0) for (k = j + 1; k <= W; k += 2) dp[1][k] += tmp;
				else for (k = j - 1; k >= 1; k -= 2) dp[1][k] += tmp;
			} else {
				if (j % 2 != 0) {
					for (k = 1; k <= W; k += 2) dp[1][k] += tmp;
					if (j != 1 && j != W) dp[1][j] -= tmp;
				}
			}
		}
		if (i == H / 2) break;
		
		for (j = 1; j <= W; j++) {
			tmp = dp[1][j] % Mod;
			dp[1][j] = 0;
			if (tmp == 0) continue;
			if (j > 1) dp[0][j-1] += tmp;
			dp[0][j] += tmp;
			if (j < W) dp[0][j+1] += tmp;
		}
	}

	long long ans = 0;
	for (j = 1; j <= W; j++) ans += dp[1][j];
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0