結果

問題 No.506 限られたジャパリまん
ユーザー furafura
提出日時 2020-06-12 11:35:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 203,684 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:56:39
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

inline int popcount(int x){
	x=((x>>1)&0x55555555)+(x&0x55555555);
	x=((x>>2)&0x33333333)+(x&0x33333333);
	x=((x>>4)+x)&0x0f0f0f0f;
	x+=(x>>8);
	x+=(x>>16);
	return x&0x3f;
}

int main(){
	int h,w,k,p; scanf("%d%d%d%d",&w,&h,&k,&p);
	vector<int> x(k),y(k);
	vector<string> s(k);
	rep(i,k) cin>>x[i]>>y[i]>>s[i];

	lint ans=0;
	int S_ans=0;
	rep(S,1<<k) if(popcount(S)==p) {
		bool ng[33][33]={};
		rep(i,k) if((S>>i&1)==0) ng[y[i]][x[i]]=true;

		lint dp[33][33]={1};
		rep(i,h+1) rep(j,w+1) if(!ng[i][j]) {
			if(i<h) dp[i+1][j]+=dp[i][j];
			if(j<w) dp[i][j+1]+=dp[i][j];
		}
		if(ans<dp[h][w]){
			ans=dp[h][w];
			S_ans=S;
		}
	}

	cout<<ans%1000000007<<'\n';
	rep(i,k) if(S_ans>>i&1) cout<<s[i]<<'\n';

	return 0;
}
0