結果
| 問題 |
No.2675 KUMA
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-15 21:54:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,045 bytes |
| コンパイル時間 | 1,002 ms |
| コンパイル使用メモリ | 92,696 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-09-30 00:58:25 |
| 合計ジャッジ時間 | 2,438 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 47 |
コンパイルメッセージ
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)
| ^
ソースコード
#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;
}