結果

問題 No.506 限られたジャパリまん
ユーザー furafura
提出日時 2020-06-12 11:33:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 832 bytes
コンパイル時間 2,044 ms
コンパイル使用メモリ 202,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:56:37
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
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 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,376 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",&h,&w,&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