結果

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

ソースコード

diff #

import sys

def can_assign(k, tasks, T):
    tasks.sort(reverse=True)
    n = len(tasks)
    times = [0] * k

    def backtrack(index):
        if index == n:
            return True
        current_t = tasks[index]
        for i in range(k):
            if i > 0 and times[i] == times[i-1]:
                continue
            if times[i] + current_t <= T:
                times[i] += current_t
                if backtrack(index + 1):
                    return True
                times[i] -= current_t
                if times[i] == 0:
                    break
        return False

    return backtrack(0)

def main():
    T = int(sys.stdin.readline())
    N = int(sys.stdin.readline())
    t = [int(sys.stdin.readline()) for _ in range(N)]
    sum_t = sum(t)
    min_k = (sum_t + T - 1) // T
    for k in range(min_k, N + 1):
        if can_assign(k, t, T):
            print(k)
            return
    print(N)

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