結果

問題 No.2675 KUMA
ユーザー AerenAeren
提出日時 2024-03-15 23:23:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,613 bytes
コンパイル時間 3,304 ms
コンパイル使用メモリ 262,936 KB
実行使用メモリ 10,260 KB
最終ジャッジ日時 2024-03-15 23:24:04
合計ジャッジ時間 7,302 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 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 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
template<class T> T &ctmin(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmin(T &x, const Head &h, const Tail &... t){ return ctmin(x = min<T>(x, h), t...); }
template<class T> T &ctmax(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmax(T &x, const Head &h, const Tail &... t){ return ctmax(x = max<T>(x, h), t...); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	static const vector<pair<int, int>> dr8{{2, 1}, {1, 2}, {1, -2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};
	int n;
	cin >> n;
	set<array<int, 2>> appear;
	map<array<int, 2>, int> mask;
	for(auto i = 0; i < n; ++ i){
		int x, y;
		cin >> x >> y;
		appear.insert({x, y});
		for(auto [dx, dy]: dr8){
			mask[{x + dx, y + dy}] |= 1 << i;
		}
	}
	for(auto [x, y]: appear){
		mask.erase({x, y});
	}
	const int inf = numeric_limits<int>::max() / 2;
	vector<int> dp(1 << n, inf);
	dp[0] = 0;
	for(auto [pos, m]: mask){
		for(auto smask = m; smask; smask = smask - 1 & m){
			ctmin(dp[smask], 1);
		}
	}
	for(auto i = 0; i < 32; ++ i){
		for(auto mask = 1; mask < 1 << n; ++ mask){
			for(auto smask = mask; smask; smask = smask - 1 & mask){
				ctmin(dp[mask], dp[smask] + dp[smask ^ mask]);
			}
			for(auto smask = mask; smask; smask = smask - 1 & mask){
				ctmin(dp[smask], dp[mask]);
			}
		}
	}
	dp.back() == inf ? cout << "-1\n" : cout << dp.back() << "\n";
	return 0;
}

/*

*/
0