#include using namespace std; // 負の座標には置けないと勘違いしている解法を落とす int main() { int N; cin >> N; vector x(N), y(N); // その座標にいる UMA の集合を bit で持っておく。 int uma_set[1100][1100] = {}; for (int i = 0; i < N; i++) { cin >> x[i] >> y[i]; x[i] += 5; y[i] += 5; uma_set[x[i]][y[i]] = (1 << i); } // 設置する点の候補を列挙 set> candidates; const int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}; const int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; for (int i = 0; i < N; i++) { for (int j = 0; j < 8; j++) { candidates.insert({x[i] + dx[j], y[i] + dy[j]}); } } // UMA のいる場所を除く for (int i = 0; i < N; i++) { pair p = {x[i], y[i]}; if (candidates.count(p)) candidates.erase(p); } // dp vector dp(1 << N, numeric_limits::max()); dp[0] = 0; for (auto &&[a, b] : candidates) { auto new_dp = dp; // 負の座標には置かない(5ずつ入力に加えている) if (a < 5 || b < 5) continue; for (int bits = 0; bits < (1 << N); bits++) { if (dp[bits] == numeric_limits::max()) continue; const int dx1[] = {-1, -1, +2, -2}; const int dy1[] = {+2, -2, -1, -1}; const int dx2[] = {+1, +1, +2, -2}; const int dy2[] = {+2, -2, +1, +1}; for (int dir = 0; dir < 4; dir++) { int bits_next = bits; // 向いた先の UMA を bits_next に加える bits_next |= uma_set[a + dx1[dir]][b + dy1[dir]]; bits_next |= uma_set[a + dx2[dir]][b + dy2[dir]]; new_dp[bits_next] = min(new_dp[bits_next], dp[bits] + 1); } } dp.swap(new_dp); } cout << (dp.back() != numeric_limits::max() ? dp.back() : -1) << endl; }