結果

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

ソースコード

diff #

import sys

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)
    t_sorted = sorted(t, reverse=True)
    
    for k in range(1, N + 1):
        if sum_t > k * T:
            continue
        if any(x > T for x in t_sorted):
            continue
        
        sums = [0] * k
        success = False
        
        def backtrack(index):
            nonlocal success
            if success:
                return
            if index == len(t_sorted):
                success = True
                return
            task = t_sorted[index]
            for i in range(k):
                if sums[i] + task > T:
                    continue
                if i > 0 and sums[i] == sums[i - 1]:
                    continue
                sums[i] += task
                backtrack(index + 1)
                if success:
                    return
                sums[i] -= task
        
        backtrack(0)
        if success:
            print(k)
            return
    
    print(N)

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