結果

問題 No.506 限られたジャパリまん
ユーザー gigimegigime
提出日時 2017-04-21 22:58:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,341 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 180,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:51:28
合計ジャッジ時間 3,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int H,W,K,P;
vector<int> X,Y;
vector<string> name;
ll memo [100] [100];
const ll MOD = 1e9 + 7;

int bit_count(int x)
{
	int res = 0;
	for(;x;x -= x & -x) res++;
	return res;
}

ll rec(ll y,ll x,set< pair<int,int> >& st)
{
	if(st.count(make_pair(y,x))) return 0ll;
	if(memo [y] [x] != -1) return memo [y] [x];
	ll res = 0;
	if(y) res += rec(y - 1,x,st);
	if(x) res += rec(y,x - 1,st);
	return memo [y] [x] = res;
}

int main()
{
	cin >> H >> W >> K >> P;
	X.assign(K,0);
	Y.assign(K,0);
	name.assign(K,"");
	FOR(i,0,K){
		cin >> X [i] >> Y [i] >> name [i];
	}
	ll mx = 0;
	vector<string> ans;
	FOR(i,0,1 << K) if(bit_count(i) == P){
		memset(memo,-1,sizeof(memo));
		memo [0] [0] = 1;
		set< pair<int,int> > st;
		FOR(j,0,K) if((i >> j & 1) == 0){
			st.insert(make_pair(Y [j],X [j]));
		}
		if(chmax(mx,rec(W,H,st))){
			ans.clear();
			FOR(j,0,K) if(i >> j & 1){
				ans.push_back(name [j]);
			}
		}
	}

	cout << mx % MOD << endl;
	FOR(i,0,ans.size()){
		cout << ans [i] << endl;
	}

	return 0;
}
0