結果

問題 No.506 限られたジャパリまん
ユーザー ldsybldsyb
提出日時 2017-04-22 00:16:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 69,864 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-10 12:52:53
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 AC 69 ms
4,380 KB
testcase_05 AC 69 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 31 ms
4,384 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 7 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 33 ms
4,380 KB
testcase_21 AC 33 ms
4,380 KB
testcase_22 AC 62 ms
4,376 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

using ll = long long;

int bitcount(int a){
	int r = 0;
	while(a){
		a -= a & -a;
		r++;
	}
	return r;
}

int main(){
	int h, w, k, p, ans = -1;
	cin >> h >> w >> k >> p;
	ll maxi = -1;
	int x[k], y[k];
	string n[k];
	for(int i = 0; i < k; i++) cin >> x[i] >> y[i] >> n[i];
	for(int puni = 0; puni < 1 << k; puni++){
		if(p < bitcount(puni)) continue;
		ll dp[h + 1][w + 1];
		fill(dp[0], dp[h + 1], -1);
		for(int i = 0; i < h + 1; i++) dp[i][0] = 1;
		for(int i = 0; i < w + 1; i++) dp[0][i] = 1;
		for(int i = 0; i < k; i++) if(!(puni >> i & 1)) dp[x[i]][y[i]] = 0;
		for(int i = 1; i < h + 1; i++) for(int j = 1; j < w + 1; j++) if(dp[i][j]){
			dp[i][j] = max(dp[i][j], dp[i - 1][j] + dp[i][j - 1]);
		}
		if(maxi < dp[h][w]){
			maxi = dp[h][w];
			ans = puni;
		}
	}
	if(maxi == -1){
		cout << 0 << endl;
		return 0;
	}
	cout << maxi % ll(1e9 + 7) << endl;
	for(int i = 0; i < k; i++) if(ans >> i & 1) cout << n[i] << endl;
}
0