結果

問題 No.10 +か×か
ユーザー roarisroaris
提出日時 2020-07-25 22:09:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 341 ms / 5,000 ms
コード長 540 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 115,916 KB
最終ジャッジ日時 2023-08-21 06:31:25
合計ジャッジ時間 3,235 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,140 KB
testcase_01 AC 71 ms
71,436 KB
testcase_02 AC 74 ms
71,192 KB
testcase_03 AC 341 ms
115,544 KB
testcase_04 AC 300 ms
101,944 KB
testcase_05 AC 72 ms
71,380 KB
testcase_06 AC 337 ms
115,916 KB
testcase_07 AC 280 ms
101,924 KB
testcase_08 AC 135 ms
83,732 KB
testcase_09 AC 169 ms
89,868 KB
testcase_10 AC 82 ms
76,120 KB
testcase_11 AC 77 ms
76,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
T = int(input())
A = list(map(int, input().split()))
A.reverse()
dp = [[False]*(T+1) for _ in range(N)]
dp[0][T] = True

for i in range(N-1):
    for j in range(T+1):
        if j%A[i]==0:
            dp[i+1][j//A[i]] |= dp[i][j]
        
        if j-A[i]>=0:
            dp[i+1][j-A[i]] |= dp[i][j]
        
ans = []
now = A[-1]

for i in range(N-2, -1, -1):
    if now+A[i]<=T and dp[i][now+A[i]]:
        ans.append('+')
        now += A[i]
    else:
        ans.append('*')
        now *= A[i]
    
print(''.join(ans))
0