結果

問題 No.10 +か×か
ユーザー kohei2019kohei2019
提出日時 2021-02-03 09:24:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 5,000 ms
コード長 568 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 116,140 KB
最終ジャッジ日時 2023-08-21 06:32:50
合計ジャッジ時間 3,090 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,160 KB
testcase_01 AC 72 ms
70,968 KB
testcase_02 AC 72 ms
71,040 KB
testcase_03 AC 326 ms
115,952 KB
testcase_04 AC 267 ms
102,980 KB
testcase_05 AC 72 ms
71,256 KB
testcase_06 AC 326 ms
116,140 KB
testcase_07 AC 290 ms
102,400 KB
testcase_08 AC 132 ms
83,780 KB
testcase_09 AC 170 ms
90,576 KB
testcase_10 AC 84 ms
75,976 KB
testcase_11 AC 80 ms
75,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
total = int(input())
lsA = list(map(int,input().split()))
dp = [[False]*(total+1) for i in range(N+1)]
dp[N][total] = True
for i in range(N-1,-1,-1):
    k = lsA[i]
    for j in range(total+1):
        if j%k == 0:
            dp[i][j//k] = dp[i][j//k] or dp[i+1][j]
        if j-k >= 0:
            dp[i][j-k] = dp[i][j-k] or dp[i+1][j]
v = lsA[0]
ans = []
for i in range(2,N+1):
    if v+lsA[i-1] <= total and dp[i][v+lsA[i-1]]:
        ans.append('+')
        v += lsA[i-1]
    else:
        ans.append('*')
        v *= lsA[i-1]
print(*ans,sep='')
0