結果

問題 No.506 限られたジャパリまん
ユーザー kotamanegikotamanegi
提出日時 2017-04-21 22:47:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 95,252 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 12:51:02
合計ジャッジ時間 2,536 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 117 ms
4,376 KB
testcase_05 AC 116 ms
4,380 KB
testcase_06 AC 2 ms
4,504 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 29 ms
4,376 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 56 ms
4,376 KB
testcase_12 AC 25 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 27 ms
4,380 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 30 ms
4,380 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 58 ms
4,380 KB
testcase_21 AC 58 ms
4,376 KB
testcase_22 AC 111 ms
4,376 KB
testcase_23 AC 28 ms
4,380 KB
testcase_24 AC 13 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int grid[40][40] = {};
int main() {
#define int long long
	int h, w, k, p;
	cin >> h >> w >> k >> p;
	vector<string> names;
	vector<pair<int, int>> nyao;
	REP(i, k) {
		int a, b;
		cin >> a >> b;
		string hoge;
		cin >> hoge;
		nyao.push_back(make_pair(a, b));
		grid[a][b] = 1;
		names.push_back(hoge);
	}
	long long ans = 0;
	vector<string> gogo;
	for (int i = 0;i < (1 << k);++i) {
		vector<string> now;
		int aaa = i;
		int cnt = 0;
		int gya = 0;
		while (aaa != 0) {
			if (aaa % 2 == 1) {
				grid[nyao[cnt].first][nyao[cnt].second] = false;
				now.push_back(names[cnt]);
				gya++;
			}
			aaa /= 2;
			cnt++;
		}
		if (gya <= p) {
			long long decide[40][40] = {};
			decide[0][0] = 1;
			for (int i = 0;i <= h;++i) {
				for (int q = 0;q <= w;++q) {
					if (grid[i][q] == false) {
						if (q != 0) decide[i][q] += decide[i][q - 1];
						if (i != 0) decide[i][q] += decide[i - 1][q];
					}
				}
			}
			if (ans < decide[h][w]) {
				ans = decide[h][w];
				gogo = now;
			}
		}
		aaa = i;
		cnt = 0;
		while (aaa != 0) {
			if (aaa % 2 == 1) {
				grid[nyao[cnt].first][nyao[cnt].second] = true;
				gya++;
			}
			aaa /= 2;
			cnt++;
		}
	}
	cout << ans%MAX_MOD << endl;
	for (int i = 0;i < gogo.size();++i) {
		cout << gogo[i] << endl;
	}
	return 0;
}
0