結果

問題 No.733 分身並列コーディング
ユーザー tcltk
提出日時 2021-09-11 05:30:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,221 ms / 1,500 ms
コード長 834 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 91,564 KB
最終ジャッジ日時 2024-06-22 04:38:34
合計ジャッジ時間 22,260 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """5
# 3
# 1
# 5
# 3
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

T = int(input())
N = int(input())
A = [int(input()) for _ in range(N)]

dp = [INF] * (1<<N)
dp[0] = 0

for mask in range(1<<N):
    if sum(A[i] for i in range(N) if mask & (1<<i)) <= T:
        dp[mask] = 1

    else:
        t = bin(mask).count('1')
        mask1 = mask
        while mask1:
            # 処理を書く
            mask2 = mask ^ mask1
            t = min(t, dp[mask1] + dp[mask2])

            mask1 = (mask1-1) & mask
        
        dp[mask] = t

ans = dp[(1<<N)-1]
print(ans)
0