結果

問題 No.286 Modulo Discount Store
ユーザー みあえみあえ
提出日時 2024-04-03 22:03:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 602 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,232 KB
最終ジャッジ日時 2024-04-03 22:03:25
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 80 ms
72,216 KB
testcase_02 AC 247 ms
77,068 KB
testcase_03 AC 40 ms
59,076 KB
testcase_04 AC 47 ms
63,644 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 351 ms
77,308 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 210 ms
77,340 KB
testcase_11 AC 46 ms
59,076 KB
testcase_12 AC 39 ms
59,076 KB
testcase_13 AC 252 ms
77,196 KB
testcase_14 AC 36 ms
53,460 KB
testcase_15 AC 36 ms
53,460 KB
testcase_16 AC 66 ms
72,216 KB
testcase_17 AC 602 ms
78,232 KB
testcase_18 AC 216 ms
77,340 KB
testcase_19 AC 36 ms
53,460 KB
testcase_20 AC 127 ms
76,916 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 36 ms
53,460 KB
testcase_23 AC 238 ms
76,940 KB
testcase_24 AC 36 ms
53,460 KB
testcase_25 AC 147 ms
76,732 KB
testcase_26 AC 39 ms
53,460 KB
testcase_27 AC 150 ms
76,988 KB
testcase_28 AC 376 ms
77,828 KB
testcase_29 AC 35 ms
53,460 KB
testcase_30 AC 35 ms
53,460 KB
testcase_31 AC 101 ms
76,532 KB
testcase_32 AC 101 ms
76,532 KB
testcase_33 AC 37 ms
53,460 KB
testcase_34 AC 38 ms
53,460 KB
testcase_35 AC 72 ms
72,216 KB
testcase_36 AC 39 ms
53,460 KB
testcase_37 AC 161 ms
76,732 KB
testcase_38 AC 36 ms
53,460 KB
testcase_39 AC 363 ms
77,820 KB
testcase_40 AC 36 ms
53,460 KB
testcase_41 AC 36 ms
53,460 KB
testcase_42 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(N, A):
    dp = [float("inf")] * (1 << N)
    dp[0] = 0
    for V in range(1 << N):
        for i in range(N):
            if (V >> i) & 1:
                continue
            VV = V | (1 << i)
            r = (
                sum(a for b, a in zip(list(f"{V:0{N}b}"[::-1]), A) if b == "1")
                % 1000
            )
            buy = max(0, A[i] - r)
            dp[VV] = min(dp[VV], dp[V] + buy)

    return dp[-1]


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = solve(N, A)
    print(ans)


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