結果

問題 No.506 限られたジャパリまん
ユーザー antaanta
提出日時 2017-04-21 22:45:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 1,625 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 179,232 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:51:00
合計ジャッジ時間 3,906 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 173 ms
4,376 KB
testcase_05 AC 174 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 37 ms
4,376 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 92 ms
4,376 KB
testcase_12 AC 47 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 24 ms
4,380 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 AC 57 ms
4,380 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 85 ms
4,376 KB
testcase_21 AC 85 ms
4,376 KB
testcase_22 AC 165 ms
4,376 KB
testcase_23 AC 42 ms
4,380 KB
testcase_24 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int H; int W; int K; int P;
	while (~scanf("%d%d%d%d", &H, &W, &K, &P)) {
		++H, ++W;
		vpii v(K);
		vector<string> names(K);
		rep(i, K) {
			int y; int x;
			scanf("%d%d", &y, &x);
			char buf[101];
			scanf("%s", buf);
			v[i] = { y,x };
			names[i] = buf;
		}
		pair<ll, int> ans(0, 0);
		rep(S, 1 << K) {
			vector<bool> blocked(H * W);
			int pcnt = 0;
			rep(i, K) {
				int y, x;
				tie(y, x) = v[i];
				if (S >> i & 1) {
					++ pcnt;
				} else {
					blocked[y * W + x] = true;
				}
			}
			if (pcnt > P)continue;
			vector<vector<ll>> dp(H, vector<ll>(W));
			if (!blocked[0]) dp[0][0] = 1;
			rep(i, H) rep(j, W) {
				ll x = dp[i][j];
				if (x == 0) continue;
				if (i + 1 < H && !blocked[(i + 1)*W + j])
					dp[i + 1][j] += x;
				if (j + 1 < W && !blocked[i*W + (j + 1)])
					dp[i][j + 1] += x;
			}
			amax(ans, make_pair(dp[H - 1][W - 1], S));
		}
		printf("%lld\n", ans.first % 1000000007);
		if (ans.first != 0) {
			rep(i, K) if (ans.second >> i & 1)
				puts(names[i].c_str());
		}
	}
	return 0;
}
0