結果

問題 No.2675 KUMA
ユーザー 👑 rin204rin204
提出日時 2024-03-15 22:00:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,796 KB
最終ジャッジ日時 2024-03-15 22:00:26
合計ジャッジ時間 5,641 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 50 ms
64,052 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 41 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 212 ms
75,732 KB
testcase_06 AC 159 ms
75,748 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 225 ms
75,760 KB
testcase_09 AC 149 ms
75,508 KB
testcase_10 AC 222 ms
75,756 KB
testcase_11 AC 217 ms
75,756 KB
testcase_12 AC 71 ms
64,080 KB
testcase_13 AC 53 ms
64,504 KB
testcase_14 AC 51 ms
64,068 KB
testcase_15 AC 38 ms
53,460 KB
testcase_16 AC 129 ms
64,600 KB
testcase_17 AC 37 ms
53,460 KB
testcase_18 AC 38 ms
53,460 KB
testcase_19 AC 39 ms
53,460 KB
testcase_20 AC 38 ms
53,460 KB
testcase_21 AC 38 ms
53,460 KB
testcase_22 AC 43 ms
59,704 KB
testcase_23 AC 42 ms
59,576 KB
testcase_24 AC 47 ms
61,848 KB
testcase_25 AC 46 ms
61,844 KB
testcase_26 AC 45 ms
59,704 KB
testcase_27 AC 48 ms
61,984 KB
testcase_28 AC 53 ms
64,328 KB
testcase_29 AC 54 ms
64,484 KB
testcase_30 AC 51 ms
61,988 KB
testcase_31 AC 61 ms
66,132 KB
testcase_32 AC 52 ms
64,064 KB
testcase_33 AC 51 ms
64,064 KB
testcase_34 AC 51 ms
64,064 KB
testcase_35 AC 55 ms
66,120 KB
testcase_36 AC 62 ms
68,216 KB
testcase_37 AC 65 ms
68,224 KB
testcase_38 AC 67 ms
68,216 KB
testcase_39 AC 71 ms
72,340 KB
testcase_40 AC 69 ms
70,272 KB
testcase_41 AC 89 ms
75,400 KB
testcase_42 AC 92 ms
75,324 KB
testcase_43 AC 88 ms
75,400 KB
testcase_44 AC 94 ms
75,368 KB
testcase_45 AC 130 ms
75,456 KB
testcase_46 AC 107 ms
75,616 KB
testcase_47 AC 112 ms
75,564 KB
testcase_48 AC 159 ms
75,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
xy = {}
inds = set()

di = [1, -1, 2, 2, 1, -1, -2, -2]
dj = [2, 2, 1, -1, -2, -2, 1, -1]
for i in range(n):
    x, y = map(int, input().split())
    xy[(x, y)] = i
    for k in range(8):
        inds.add((x + di[k], y + dj[k]))


dp = [1 << 30] * (1 << n)
dp[0] = 0


for x, y in inds:
    if (x, y) in xy:
        continue
    ok = []
    for k in range(0, 8, 2):
        x1 = x + di[k]
        y1 = y + dj[k]
        x2 = x + di[k + 1]
        y2 = y + dj[k + 1]
        if (x1, y1) in xy and (x2, y2) in xy:
            ok.append((1 << xy[(x1, y1)]) | (1 << xy[(x2, y2)]))

        if (x1, y1) in xy:
            ok.append(1 << xy[(x1, y1)])
        if (x2, y2) in xy:
            ok.append(1 << xy[(x2, y2)])

    for bit in range((1 << n) - 1, -1, -1):
        for bit2 in ok:
            if (bit & bit2) == bit2:
                dp[bit] = min(dp[bit], dp[bit ^ bit2] + 1)

if dp[-1] > n:
    print(-1)
else:
    print(dp[-1])
0