結果

問題 No.10 +か×か
ユーザー matsu7874matsu7874
提出日時 2015-08-20 19:40:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,787 ms / 5,000 ms
コード長 779 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 19,260 KB
最終ジャッジ日時 2023-08-21 06:13:54
合計ジャッジ時間 5,892 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,804 KB
testcase_01 AC 16 ms
7,764 KB
testcase_02 AC 16 ms
7,896 KB
testcase_03 AC 1,787 ms
19,260 KB
testcase_04 AC 274 ms
10,680 KB
testcase_05 AC 16 ms
7,792 KB
testcase_06 AC 1,773 ms
18,448 KB
testcase_07 AC 799 ms
16,208 KB
testcase_08 AC 160 ms
10,788 KB
testcase_09 AC 191 ms
11,876 KB
testcase_10 AC 17 ms
8,192 KB
testcase_11 AC 16 ms
8,204 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+1):
            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