結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,748 KB
testcase_01 AC 16 ms
7,852 KB
testcase_02 AC 16 ms
7,668 KB
testcase_03 AC 1,818 ms
19,200 KB
testcase_04 AC 281 ms
10,628 KB
testcase_05 RE -
testcase_06 AC 1,803 ms
18,340 KB
testcase_07 WA -
testcase_08 AC 161 ms
10,800 KB
testcase_09 AC 195 ms
11,696 KB
testcase_10 AC 18 ms
8,048 KB
testcase_11 AC 16 ms
8,268 KB
権限があれば一括ダウンロードができます

ソースコード

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