QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673417#8783. Cherry PickingmalkovskyWA 14ms10744kbPython31.8kb2024-10-24 22:16:122024-10-24 22:16:12

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 22:16:12]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:10744kb
  • [2024-10-24 22:16:12]
  • 提交

answer


def __main__():
    sorted_players = dict()
    n, k = map(int, input().split())
    ratings = list(map(int, input().split()))
    result = input()

    left = [i for i in range(n)]
    def get_left(i):
        while i != left[i]:
            i = left[i]
        return left[i]
    right = [i + 1 for i in range(n)]
    size = [1 for i in range(n)]

    num_at_least_k = 0

    for i in range(0, n):
        if i > 0 and result[i] == result[i - 1]:
            left[i] = left[i - 1]
            right[left[i]] = right[i]
            size[left[i]] += 1
            if size[left[i]] >= k:
                num_at_least_k += 1

        if k == 1:
            num_at_least_k += int(result[i])

        if ratings[i] not in sorted_players:
            sorted_players[ratings[i]] = []

        sorted_players[ratings[i]].append(i)

    # print(left,right, size)
    # print(num_at_least_k)
    answer = 0
    for r, players in sorted(sorted_players.items(), key=lambda x: x[0]):
        for player in players:
            seg = get_left(player)

            size[seg] -= 1;
            if size[seg] == k - 1 and result[seg] == "1":
                num_at_least_k -= 1
            # print("removed", player, seg, size[seg])
            if size[seg] == 0:
                if right[seg] < n and seg > 0:
                    left[right[seg]] = get_left(seg - 1)
                    right[left[right[seg]]] = right[right[seg]]
                    size[left[right[seg]]] += size[right[seg]]
                    # print("Merged", left[right[seg]], right[right[seg]])
                    if size[left[right[seg]]] >= k and result[left[right[seg]]] == "1":
                        num_at_least_k += 1

        if num_at_least_k > 0:
            answer = r + 1
        # print(num_at_least_k)

    print(answer)










__main__()
#%%

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 10608kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 14ms
memory: 10744kb

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 10704kb

input:

1 1
1
1

output:

0

result:

wrong answer expected '1', found '0'