結果

問題 No.10 +か×か
ユーザー matsu7874matsu7874
提出日時 2015-08-20 19:32:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 777 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 19,148 KB
最終ジャッジ日時 2023-09-25 13:55:17
合計ジャッジ時間 6,119 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    INF = float('inf')
    N = int(input())
    Total = int(input())
    A = [int(x) for x in input().split()]
    dp = [INF for i in range(Total + 1)]
    dp[A[0]] = 0
    for i in range(1,N):
        dp_next = [INF for i in range(Total + 1)]
        for j in range(Total):
            if dp[j] == INF:
                continue
            if j + A[i] <= Total:
                dp_next[j + A[i]] = min(dp_next[j + A[i]], dp[j] * 2)
            if j * A[i] <= Total:
                dp_next[j * A[i]] = min(dp_next[j * A[i]], dp[j] * 2 + 1)
        dp = dp_next[:]
    for i in range(N-1):
        if (dp[Total] >> (N - 2 - i)) % 2 == 1:
            print('+', end='')
        else:
            print('*', end='')
    print()

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