結果

問題 No.2675 KUMA
ユーザー Jinapetto
提出日時 2024-03-18 19:33:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 3,104 ms
コンパイル使用メモリ 260,700 KB
実行使用メモリ 36,992 KB
最終ジャッジ日時 2024-09-30 05:01:14
合計ジャッジ時間 6,349 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;

//多倍長整数//
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;

const int INF = 1e9;
const int MOD = 998244353;
const long long LINF = 4e18;

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vvvvl = vector<vector<vector<vector<long long>>>>;
using vvc = vector<vector<char>>;
using vvb = vector<vector<bool>>;
using vvvb = vector<vector<vector<bool>>>;
using vvvvb = vector<vector<vector<vector<bool>>>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ALL(obj) (obj).begin(),(obj).end()

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vi x(n),y(n);
	rep(i,n) cin >> x[i] >> y[i];
	vvi dx = {{-1,1},{2,2},{1,-1},{-2,-2}};
	vvi dy = {{2,2},{1,-1},{-2,-2},{-1,1}};
	vector<pair<int,int>> s;
	vi da = {-1,1,2,2,1,-1,-2,-2};
	vi db = {2,2,1,-1,-2,-2,-1,1};
	rep(i,n){
		rep(j,8){
			bool ok = true;
			rep(k,n) if(x[i] + da[j] == x[k] && y[i] + db[j] == y[k]) ok = false;
			if(ok) s.push_back({x[i] + da[j],y[i] + db[j]});
		}
	}
	sort(ALL(s));
	s.erase(unique(ALL(s)),s.end());
	//rep(i,s.size()) cout << s[i].first << ' ' << s[i].second << endl;
	vvi dp(s.size() + 1,vi(1<<n,INF));
	dp[0][0] = 0;
	rep(i,s.size()){
		rep(j,(1<<n)){
			if(dp[i][j] == INF) continue;
			dp[i + 1][j] = min(dp[i + 1][j],dp[i][j]);
			rep(k,4){
				int bit = j;
				rep(l,n){
					rep(m,2){
						if(s[i].first + dx[k][m] == x[l] && s[i].second + dy[k][m] == y[l]) bit = (bit | (1<<l));
					}
				}
				//cout << bit << endl;
				dp[i + 1][bit] = min(dp[i + 1][bit],dp[i][j] + 1);
			}
		}
	}
	if(dp[s.size()][(1<<n) - 1] == INF) cout << -1 << endl;
	else cout << dp[s.size()][(1<<n) - 1] << endl;
	return 0;
}
0