結果

問題 No.2675 KUMA
ユーザー binapbinap
提出日時 2024-03-15 23:23:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 2,389 bytes
コンパイル時間 5,190 ms
コンパイル使用メモリ 278,424 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 23:23:21
合計ジャッジ時間 6,810 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 56 ms
6,676 KB
testcase_06 AC 41 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 61 ms
6,676 KB
testcase_09 AC 25 ms
6,676 KB
testcase_10 AC 69 ms
6,676 KB
testcase_11 AC 63 ms
6,676 KB
testcase_12 AC 26 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 109 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 3 ms
6,676 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 4 ms
6,676 KB
testcase_36 AC 6 ms
6,676 KB
testcase_37 AC 6 ms
6,676 KB
testcase_38 AC 10 ms
6,676 KB
testcase_39 AC 10 ms
6,676 KB
testcase_40 AC 10 ms
6,676 KB
testcase_41 AC 18 ms
6,676 KB
testcase_42 AC 18 ms
6,676 KB
testcase_43 AC 20 ms
6,676 KB
testcase_44 AC 18 ms
6,676 KB
testcase_45 AC 39 ms
6,676 KB
testcase_46 AC 38 ms
6,676 KB
testcase_47 AC 38 ms
6,676 KB
testcase_48 AC 65 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}

int main(){
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	map<pair<int, int>, vector<vector<int>>> ma;
	vector<tuple<int, int, int>> v = {{0, 2, 1}, {0, 2, -1}, {1, 1, 2}, {1, -1, 2}, {2, -2, 1}, {2, -2, -1}, {3, 1, -2}, {3, -1, -2}};
	rep(i, n){
		for(auto [dir, dy, dx] : v){
			pair<int, int> p = {y[i] + dy, x[i] + dx};
			if(ma.find(p) == ma.end()) ma[p].resize(4);
			ma[p][dir].push_back(i);
		}
	}
	{
		vector<pair<int, int>> del;
		rep(i, n){
			pair<int, int> p = {y[i], x[i]};
			if(ma.find(p) == ma.end()) continue;
			del.push_back(p);
		}
		for(auto p : del) ma.erase(p);
	}
	const int INF = 1001001;
	vector<int> dp(1 << n, INF);
	dp[0] = 0;
	for(auto& [p, vec] : ma){
		vector<int> dp_old(1 << n, INF);
		swap(dp, dp_old);
		rep(bit, 1 << n){
			rep(dir, 4){
				int bit_new = bit;
				for(auto idx : vec[dir]) bit_new |= (1 << idx);
				chmin(dp[bit_new], dp_old[bit] + 1);
				chmin(dp[bit], dp_old[bit]);
			}
		}
	}
	int ans = dp[(1 << n) -1];
	if(ans >= INF) cout << "-1\n";
	else cout << ans << "\n";
	return 0;
}
0