QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#439098#4954. Eliminating BallonssergiolozavRE 0ms0kbPython32.6kb2024-06-11 16:06:462024-06-11 16:06:46

Judging History

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

  • [2024-06-11 16:06:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-06-11 16:06:46]
  • 提交

answer

import timeit

class Stopwatch:
    hide = False

    def __init__(self, name):
        self.time = 0
        self.calls = 0
        self.name = name
        self.current_execution = 0
    
    def start_cumulative(self):
        if Stopwatch.hide:
            return

        self.current_execution = timeit.default_timer()
        self.calls += 1
    
    def stop_cumulative(self):
        if Stopwatch.hide:
            return

        assert self.current_execution != 0, "'start_cumulative' must be called before 'stop_cumulative'"
        elapsed = timeit.default_timer() - self.current_execution
        self.current_execution = 0
        self.time += elapsed
    
    def print(self):
        if not Stopwatch.hide:
            print(self)

    def __repr__(self) -> str:
        return f"{self.name} - {self.time}s - {self.calls}"
    

#input()
#heights = list(map(int, input().split()))

from cases import heights  

import bisect

Stopwatch.hide = True
a = Stopwatch("height_time")
b = Stopwatch("find_children")
c = Stopwatch("total")
d = Stopwatch("bisect")
e = Stopwatch("pop")

c.start_cumulative()

def build_height_map(heights):
    map = {}
    highest_balloon = heights[0]

    for index, height in enumerate(heights):
        if height > highest_balloon:
            highest_balloon = height

        if map.get(height):
            map[height].append(index)
            continue
        map[height] = [index]

    for layers in map.values():
        layers.sort()


    return map, highest_balloon

arrows = 0

a.start_cumulative()
heights_map, start_height = build_height_map(heights)
a.stop_cumulative()
a.print()

current_height = start_height
while current_height != 0:

    height_layer = heights_map.get(current_height)

    if not height_layer:
        current_height -= 1
        continue

    index = height_layer.pop(0)
    arrows += 1

    start_height = current_height
    start_height -= 1
    might_pop_list = heights_map.get(start_height)

    b.start_cumulative()
    while might_pop_list:

        d.start_cumulative()
        index_index = bisect.bisect_left(might_pop_list, index)
        d.stop_cumulative()

        if index_index == len(might_pop_list):
            break
        might_pop_index = might_pop_list[index_index]

        e.start_cumulative()
        might_pop_list.pop(index_index)
        e.stop_cumulative()

        start_height -= 1
        might_pop_list = heights_map.get(start_height)
        index = might_pop_index

    b.stop_cumulative()

b.print()

print(arrows)

c.stop_cumulative()
d.print()
c.print()
e.print()

详细

Test #1:

score: 0
Dangerous Syscalls

input:

5
3 2 1 5 4

output:


result: