結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 19 ms
6,548 KB
testcase_06 AC 14 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 23 ms
6,548 KB
testcase_11 AC 22 ms
6,548 KB
testcase_12 AC 9 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 37 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 1 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 1 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 4 ms
6,548 KB
testcase_37 AC 3 ms
6,548 KB
testcase_38 AC 5 ms
6,548 KB
testcase_39 AC 5 ms
6,548 KB
testcase_40 AC 4 ms
6,548 KB
testcase_41 AC 7 ms
6,548 KB
testcase_42 AC 7 ms
6,548 KB
testcase_43 AC 7 ms
6,548 KB
testcase_44 AC 7 ms
6,548 KB
testcase_45 AC 14 ms
6,548 KB
testcase_46 AC 13 ms
6,548 KB
testcase_47 AC 14 ms
6,548 KB
testcase_48 AC 23 ms
6,548 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;
		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;
			}
			for(int k=(1<<N)-1;k>=0;k--)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