結果

問題 No.506 限られたジャパリまん
ユーザー olpheolphe
提出日時 2017-04-21 23:13:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,983 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 114,920 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 12:52:12
合計ジャッジ時間 2,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int H, W, K, P;
string S[20];
int x[20];
int y[20];
vector<int>box;
long long int ans=0;

void Search(vector<int>s) {
	long long int dis[33][33] = {};
	for (auto i : s) {
		if (!x[i] && !y[i])return;
	}
	dis[0][0] = 1;
	for (int i = 0; i <= H; i++){
		for (int j = 0; j <= W; j++) {
			if (i&&j) {
				bool flag = true;
				for (auto k : s) {
					if (i == y[k] && j == x[k])flag = false;
				}
				if (!flag)continue;
				dis[i][j] = dis[i][j - 1];
				dis[i][j] += dis[i - 1][j];
				//dis[i][j] %= MOD;
			}
			else if (i) {
				bool flag = true;
				for (auto k : s) {
					if (i == y[k] && j == x[k])flag = false;
				}
				if (!flag)continue;
				dis[i][j] = dis[i-1][j];
				//dis[i][j] %= MOD;
			}
			else if (j) {
				bool flag = true;
				for (auto k : s) {
					if (i == y[k] && j == x[k])flag = false;
				}
				if (!flag)continue;
				dis[i][j] = dis[i][j-1];
				//dis[i][j] %= MOD;
			}
			//cout << i<<" "<<j<<" "<<dis[i][j] << endl;
		}
	}
	//cout << dis[H][W] << endl;
	if (ans < dis[H][W]) {
		ans = max(ans, dis[H][W]);
		//cout << s.size() << endl;
		box = s;
	}
}

int main() {
	cin >> W >> H >> K >> P;
	for (int i = 0; i < K; i++) {
		cin >> x[i] >> y[i] >> S[i];
	//	cout << x[i] << y[i] << S[i] << endl;
	}
	for (int i = 0; i < (int)pow(2, K); i++) {
		int num = i;
		vector<int>bag;
		for (int j = 0; j < K; j++) {
			if (!(num % 2))bag.push_back(j);
			num /= 2;
		}
		if (bag.size() == K - P)Search(bag);
	}
	cout << ans%MOD << endl;
	// << box.size()<< endl;
	for (int j = 0; j < K; j++) {
		bool flag = true;
		for (auto i : box) {
			if (j != i)flag = false;
		}
		if(flag)cout << S[j] << endl;
	}
	return 0;
}
0