結果

問題 No.2675 KUMA
ユーザー kotatsugamekotatsugame
提出日時 2024-03-15 21:54:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 92,944 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 21:54:54
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 26 ms
6,676 KB
testcase_06 AC 19 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 29 ms
6,676 KB
testcase_09 AC 11 ms
6,676 KB
testcase_10 AC 32 ms
6,676 KB
testcase_11 AC 30 ms
6,676 KB
testcase_12 AC 13 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 53 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 3 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 3 ms
6,676 KB
testcase_36 AC 4 ms
6,676 KB
testcase_37 AC 3 ms
6,676 KB
testcase_38 AC 6 ms
6,676 KB
testcase_39 AC 5 ms
6,676 KB
testcase_40 AC 6 ms
6,676 KB
testcase_41 AC 10 ms
6,676 KB
testcase_42 AC 10 ms
6,676 KB
testcase_43 AC 10 ms
6,676 KB
testcase_44 AC 9 ms
6,676 KB
testcase_45 AC 19 ms
6,676 KB
testcase_46 AC 19 ms
6,676 KB
testcase_47 AC 18 ms
6,676 KB
testcase_48 AC 31 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:27:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   27 |         for(auto[x,y]:ps)
      |                 ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
using namespace std;
int N,X[16],Y[16];
int dp[1<<16];
int dx[8]={2,2,1,-1,-2,-2,-1,1};
int dy[8]={1,-1,-2,-2,-1,1,2,2};
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	vector<pair<int,int> >ps;
	map<pair<int,int>,int>mp;
	for(int i=0;i<N;i++)
	{
		cin>>X[i]>>Y[i];
		mp[make_pair(X[i],Y[i])]=i;
		for(int r=0;r<8;r++)ps.push_back(make_pair(X[i]+dx[r],Y[i]+dy[r]));
	}
	sort(ps.begin(),ps.end());
	ps.erase(unique(ps.begin(),ps.end()),ps.end());
	for(int i=1;i<1<<N;i++)dp[i]=1e9;
	for(auto[x,y]:ps)
	{
		if(mp.find(make_pair(x,y))!=mp.end())continue;
		vector<int>nis;
		for(int r=0;r<8;r+=2)
		{
			int ni=0;
			for(int j=0;j<2;j++)
			{
				int tx=x+dx[r+j],ty=y+dy[r+j];
				auto it=mp.find(make_pair(tx,ty));
				if(it!=mp.end())ni|=1<<it->second;
			}
			nis.push_back(ni);
		}
		for(int k=(1<<N)-1;k>=0;k--)for(int ni:nis)dp[k|ni]=min(dp[k|ni],dp[k]+1);
	}
	int ans=dp[(1<<N)-1];
	if(ans==(int)1e9)ans=-1;
	cout<<ans<<endl;
}
0