Submission #55076417


Source Code Expand

def count_meetings(N, T, S, X):
    ants = [(X[i], S[i]) for i in range(N)]
    ants.sort()

    left_ants = [x for x, s in ants if s == '0']
    right_ants = [x for x, s in ants if s == '1']

    def binary_search(arr, value):
        low, high = 0, len(arr)
        while low < high:
            mid = (low + high) // 2
            if arr[mid] < value:
                low = mid + 1
            else:
                high = mid
        return low

    count = 0
    for right in right_ants:
        pos = binary_search(left_ants, right)
        if pos < len(left_ants):
            count += len(left_ants) - pos
        pos = binary_search(left_ants, right + 2 * T + 1)
        if pos < len(left_ants):
            count -= len(left_ants) - pos

    return count

N, T = map(int, input().split())
S = input().strip()
X = list(map(int, input().split()))

print(count_meetings(N, T, S, X))

Submission Info

Submission Time
Task D - Ghost Ants
User mu16
Language Python (PyPy 3.10-v7.3.12)
Score 350
Code Size 923 Byte
Status AC
Exec Time 433 ms
Memory 122380 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 57 ms 76468 KiB
00_sample_01.txt AC 56 ms 76712 KiB
01_random_00.txt AC 416 ms 121772 KiB
01_random_01.txt AC 277 ms 112060 KiB
01_random_02.txt AC 426 ms 121644 KiB
01_random_03.txt AC 344 ms 116008 KiB
01_random_04.txt AC 431 ms 122380 KiB
01_random_05.txt AC 245 ms 110824 KiB
01_random_06.txt AC 425 ms 122092 KiB
01_random_07.txt AC 344 ms 116012 KiB
01_random_08.txt AC 422 ms 122112 KiB
01_random_09.txt AC 369 ms 117840 KiB
01_random_10.txt AC 425 ms 122156 KiB
01_random_11.txt AC 388 ms 117772 KiB
01_random_12.txt AC 433 ms 121940 KiB
01_random_13.txt AC 319 ms 113844 KiB
01_random_14.txt AC 429 ms 121796 KiB
01_random_15.txt AC 245 ms 110620 KiB
01_random_16.txt AC 428 ms 122156 KiB
01_random_17.txt AC 335 ms 115652 KiB
01_random_18.txt AC 427 ms 122232 KiB
01_random_19.txt AC 375 ms 117996 KiB
01_random_20.txt AC 160 ms 120064 KiB
01_random_21.txt AC 156 ms 120020 KiB
01_random_22.txt AC 155 ms 120112 KiB
01_random_23.txt AC 157 ms 120544 KiB
01_random_24.txt AC 164 ms 120244 KiB
01_random_25.txt AC 163 ms 120056 KiB