結果

問題 No.506 限られたジャパリまん
ユーザー bal4ubal4u
提出日時 2019-09-06 05:59:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,704 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 30,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:55:40
合計ジャッジ時間 1,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:11:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   11 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: 備考: in expansion of macro ‘gc’
   17 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: 506 限られたジャパリまん
// 2019.9.6 bal4u

#include <stdio.h>
#include <string.h>

typedef long long ll;

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

//// 2^16までのビット数を数える popcount()と同等?
int bitcount(int x) {
	x = ((x & 0xAAAAAA) >>  1) + (x & 0x555555);
	x = ((x & 0xCCCCCC) >>  2) + (x & 0x333333);
	x = ((x & 0xF0F0F0) >>  4) + (x & 0x0F0F0F);
	x = ((x & 0x00FF00) >>  8) + (x & 0xFF00FF);
	return x;
}

#define MOD 1000000007
int H, W, K, P;
int rr[17], cc[17]; char name[17][13];
char map[35][35];
ll dp[35][35];
	
int main()
{
	int i, r, c;
	ll max; int path;
	
	H = in(), W = in(), K = in(), P = in();
	for (i = 0; i < K; i++) rr[i] = in(), cc[i] = in(), ins(name[i]);
	
	max = 0;
	int lim = 1 << K; for (i = 0; i < lim; i++) if (bitcount(i) == P) {
		memset(map, 1, sizeof(map));
		for (int j = 0; j < K; j++) if (!((i >> j) & 1)) map[rr[j]][cc[j]] = 0; // 通れないとこ
		
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for (r = 1; r <= H; r++) if (map[r][0]) dp[r][0] = dp[r-1][0];
		for (c = 1; c <= W; c++) if (map[0][c]) dp[0][c] = dp[0][c-1];
		for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) if (map[r][c])
			dp[r][c] = dp[r-1][c] + dp[r][c-1];
		
		if (dp[H][W] > max) max = dp[H][W], path = i;
	}
	printf("%d\n", max % MOD);
	if (max) for (i = 0; i < K; i++) if (path & (1 << i)) puts(name[i]);
	return 0;
}
0