結果

問題 No.733 分身並列コーディング
ユーザー gew1fw
提出日時 2025-06-12 20:47:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 1,500 ms
コード長 1,086 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 75,464 KB
最終ジャッジ日時 2025-06-12 20:47:43
合計ジャッジ時間 3,442 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def can_assign(tasks, m, T):
    tasks_sorted = sorted(tasks, reverse=True)
    bins = [0] * m

    def backtrack(index):
        if index == len(tasks_sorted):
            return True
        current = tasks_sorted[index]
        for i in range(m):
            if bins[i] + current > T:
                continue
            if i > 0 and bins[i] == bins[i-1]:
                continue
            bins[i] += current
            if backtrack(index + 1):
                return True
            bins[i] -= current
        return False
    return backtrack(0)

def main():
    T = int(sys.stdin.readline())
    N = int(sys.stdin.readline())
    tasks = []
    for _ in range(N):
        tasks.append(int(sys.stdin.readline()))
    S = sum(tasks)
    k = sum(1 for t in tasks if t > T / 2)
    m0 = max((S + T - 1) // T, k)
    tasks_sorted = sorted(tasks, reverse=True)
    for m in range(m0, N + 1):
        if can_assign(tasks_sorted, m, T):
            print(m)
            return
    print(N)  # This line is theoretically unreachable

if __name__ == "__main__":
    main()
0