結果

問題 No.2675 KUMA
ユーザー AerenAeren
提出日時 2024-03-15 23:21:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,674 bytes
コンパイル時間 3,380 ms
コンパイル使用メモリ 263,048 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 23:22:09
合計ジャッジ時間 13,314 ms
ジャッジサーバーID
(参考情報)
judge10 / 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 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,676 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 967 ms
6,676 KB
testcase_11 AC 942 ms
6,676 KB
testcase_12 AC 107 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 936 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 WA -
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 WA -
testcase_27 AC 2 ms
6,676 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

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 < 16; ++ 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 i = 0; i < n; ++ i){
			for(auto mask = 0; mask < 1 << n; ++ mask){
				if(mask >> i & 1){
					ctmin(dp[mask ^ 1 << i], dp[mask]);
				}
			}
		}
	}
	dp.back() == inf ? cout << "-1\n" : cout << dp.back() << "\n";
	return 0;
}

/*

*/
0