結果

問題 No.2375 watasou and hibit's baseball
ユーザー kotatsugame
提出日時 2023-07-07 21:37:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 69,076 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-21 17:22:19
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
bool dp[1<<14][14][14];
int N,A,B;
int X[14],Y[14],K[14];
int dist(int i,int j)
{
	return abs(X[i]-X[j])+abs(Y[i]-Y[j]);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>A>>B;
	for(int i=0;i<N;i++)cin>>X[i]>>Y[i]>>K[i];
	int ans=1;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(i!=j)
	{
		//i, j
		bool ok=false;
		{//2
			if(A<=dist(i,j))ok=true;
		}
		{//3
			if(B<=abs(K[i]-K[j]))ok=true;
		}
		if(ok)
		{
			ans=2;
			dp[1<<i|1<<j][i][j]=true;
		}
	}
	for(int i=0;i<1<<N;i++)for(int j=0;j<N;j++)for(int k=0;k<N;k++)if(dp[i][j][k])
	{
		ans=max(ans,__builtin_popcount(i));
		for(int l=0;l<N;l++)if(!(i>>l&1))
		{
			bool ok=false;
			{//3
				if(B<=abs(K[l]-K[k]))ok=true;
			}
			{//4
				if(A<=dist(j,l)+dist(k,l))ok=true;
			}
			if(ok)
			{
				dp[i|1<<l][k][l]=true;
			}
		}
	}
	cout<<ans<<endl;
}
0