結果

問題 No.506 限られたジャパリまん
ユーザー antaanta
提出日時 2017-04-21 22:30:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,609 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 178,780 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 12:50:46
合計ジャッジ時間 3,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 36 ms
4,376 KB
testcase_09 AC 15 ms
4,504 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 24 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 5 ms
4,376 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);
		if (ans.first != 0) {
			rep(i, K) if (ans.second >> i & 1)
				puts(names[i].c_str());
		}
	}
	return 0;
}
0