World Robot Contest2025-2026Algorithm Application ThemeJunior Highwrc.hao.work
WRC
Contest Archive / Structured Dossiers青少年算法应用训练档案馆

把训练题、知识点、执行证据和最终解题档案统一归档成可直接浏览的竞赛资料库。

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

完整题面 / 题解 / 运行证据

No Rounded CornersTailwind FirstDossier Ready
03-execution/run-001/source-snapshot/main.py

main.py

站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。

文件类型.py

10-cases/s3-jh-03-tech-schedule/03-execution/run-001/source-snapshot/main.py

import heapq
import sys


def solve(data: str) -> str:
    tokens = data.split()
    if not tokens:
        return ""
    it = iter(tokens)
    n = int(next(it))
    names = [""] * (n + 1)
    duration = [0] * (n + 1)
    indegree = [0] * (n + 1)
    graph = [[] for _ in range(n + 1)]
    start = [0] * (n + 1)
    end = [0] * (n + 1)
    for task_id in range(1, n + 1):
        names[task_id] = next(it)
        duration[task_id] = int(next(it))
        k = int(next(it))
        for _ in range(k):
            pre = int(next(it))
            graph[pre].append(task_id)
            indegree[task_id] += 1
    heap = [task_id for task_id in range(1, n + 1) if indegree[task_id] == 0]
    heapq.heapify(heap)
    processed = 0
    while heap:
        task = heapq.heappop(heap)
        processed += 1
        end[task] = start[task] + duration[task]
        for nxt in graph[task]:
            if end[task] > start[nxt]:
                start[nxt] = end[task]
            indegree[nxt] -= 1
            if indegree[nxt] == 0:
                heapq.heappush(heap, nxt)
    if processed != n:
        return "total_days=-1\nschedule=INVALID"
    total_days = max(end)
    schedule = "|".join(
        f"{names[i]}:{start[i]}-{end[i]}" for i in range(1, n + 1)
    )
    return f"total_days={total_days}\nschedule={schedule}"


if __name__ == "__main__":
    sys.stdout.write(solve(sys.stdin.read()).strip())
    sys.stdout.write("\n")