結果

問題 No.506 限られたジャパリまん
ユーザー pekempeypekempey
提出日時 2017-06-23 00:50:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 84,176 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:54:46
合計ジャッジ時間 3,381 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 203 ms
4,376 KB
testcase_05 AC 203 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 76 ms
4,380 KB
testcase_09 AC 42 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 114 ms
4,380 KB
testcase_12 AC 48 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 120 ms
4,376 KB
testcase_17 AC 21 ms
4,376 KB
testcase_18 AC 47 ms
4,380 KB
testcase_19 AC 75 ms
4,376 KB
testcase_20 AC 101 ms
4,376 KB
testcase_21 AC 100 ms
4,380 KB
testcase_22 AC 193 ms
4,376 KB
testcase_23 AC 50 ms
4,376 KB
testcase_24 AC 73 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int main() {
	int w, h, k, p;

	std::cin >> w >> h >> k >> p;
	w++;
	h++;

	std::vector<int> xs(k), ys(k);
	std::vector<std::string> ns(k);
	for (int i = 0; i < k; i++) {
		std::cin >> xs[i] >> ys[i] >> ns[i];
	}

	std::pair<long long, int> max;

	for (int s = 0; s < 1 << k; s++) {
		std::vector<std::vector<bool>> ban(h, std::vector<bool>(w));
		std::vector<std::vector<long long>> dp(h, std::vector<long long>(w));

		int cnt = 0;
		for (int i = 0; i < k; i++) {
			if (s >> i & 1) {
				cnt++;
			} else {
				ban[ys[i]][xs[i]] = true;
			}
		}
		if (cnt != p) continue;

		dp[0][0] = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (ban[i][j]) {
					dp[i][j] = 0;
				}
				if (i + 1 < h) {
					dp[i + 1][j] += dp[i][j];
				}
				if (j + 1 < w) {
					dp[i][j + 1] += dp[i][j];
				}
			}
		}

		if (max.first < dp[h - 1][w - 1]) {
			max.first = dp[h - 1][w - 1];
			max.second = s;
		}
	}

	std::cout << max.first % 1000000007 << std::endl;

	for (int i = 0; i < k; i++) {
		if (max.second >> i & 1) {
			std::cout << ns[i] << std::endl;
		}
	}
}
0