結果

問題 No.2375 watasou and hibit's baseball
ユーザー 👑 rin204rin204
提出日時 2023-07-07 21:42:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,152 ms / 2,000 ms
コード長 1,474 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 108,036 KB
最終ジャッジ日時 2023-09-28 22:45:31
合計ジャッジ時間 23,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,392 KB
testcase_01 AC 82 ms
71,140 KB
testcase_02 AC 80 ms
71,220 KB
testcase_03 AC 691 ms
92,456 KB
testcase_04 AC 115 ms
77,456 KB
testcase_05 AC 94 ms
76,024 KB
testcase_06 AC 1,131 ms
107,760 KB
testcase_07 AC 78 ms
71,224 KB
testcase_08 AC 299 ms
84,324 KB
testcase_09 AC 80 ms
71,544 KB
testcase_10 AC 84 ms
71,316 KB
testcase_11 AC 196 ms
78,676 KB
testcase_12 AC 839 ms
105,072 KB
testcase_13 AC 461 ms
90,292 KB
testcase_14 AC 79 ms
71,340 KB
testcase_15 AC 485 ms
83,812 KB
testcase_16 AC 468 ms
83,332 KB
testcase_17 AC 751 ms
104,996 KB
testcase_18 AC 79 ms
71,140 KB
testcase_19 AC 77 ms
71,216 KB
testcase_20 AC 214 ms
79,704 KB
testcase_21 AC 761 ms
104,804 KB
testcase_22 AC 81 ms
71,472 KB
testcase_23 AC 624 ms
104,168 KB
testcase_24 AC 705 ms
105,236 KB
testcase_25 AC 80 ms
71,296 KB
testcase_26 AC 1,018 ms
106,392 KB
testcase_27 AC 1,069 ms
107,352 KB
testcase_28 AC 1,026 ms
106,868 KB
testcase_29 AC 991 ms
106,388 KB
testcase_30 AC 1,128 ms
108,028 KB
testcase_31 AC 1,115 ms
107,296 KB
testcase_32 AC 1,152 ms
108,036 KB
testcase_33 AC 1,127 ms
107,700 KB
testcase_34 AC 930 ms
105,608 KB
testcase_35 AC 1,059 ms
105,900 KB
testcase_36 AC 971 ms
106,604 KB
testcase_37 AC 817 ms
105,472 KB
testcase_38 AC 491 ms
102,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    x += x >> 8
    x += x >> 16
    return x & 0x0000003F


n, a, b = map(int, input().split())
X = [0] * n
Y = [0] * n
K = [0] * n
for i in range(n):
    X[i], Y[i], K[i] = map(int, input().split())


def f(bit, i, j):
    return (bit * n + i) * n + j


dp = [False] * ((1 << n) * n * n)
for i in range(n):
    dp[f(1 << i, i, i)] = True


def dist(i, j):
    return abs(X[i] - X[j]) + abs(Y[i] - Y[j])


for bit in range(1 << n):
    ind = []
    for i in range(n):
        if bit >> i & 1:
            ind.append(i)

    for i in ind:
        for j in ind:
            if i == j:
                continue
            if len(ind) == 2 and a <= dist(i, j):
                dp[f(bit, i, j)] |= dp[f(bit ^ (1 << j), i, i)]
            if b <= abs(K[i] - K[j]):
                dp[f(bit, i, j)] |= dp[f(bit ^ (1 << j), i, i)]

            for k in ind:
                if k == i or k == j:
                    continue

                if a <= dist(i, k) + dist(j, k):
                    dp[f(bit, j, k)] |= dp[f(bit ^ (1 << k), i, j)]
                if b <= abs(K[j] - K[k]):
                    dp[f(bit, j, k)] |= dp[f(bit ^ (1 << k), i, j)]

ans = 0
for bit in range(1 << n):
    pc = popcount(bit)
    for i in range(n):
        for j in range(n):
            if dp[f(bit, i, j)]:
                ans = max(ans, pc)

print(ans)
0