結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2022-02-17 11:23:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,372 ms / 5,000 ms |
コード長 | 634 bytes |
コンパイル時間 | 91 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 90,880 KB |
最終ジャッジ日時 | 2024-06-29 07:33:53 |
合計ジャッジ時間 | 6,843 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
N = int(input())total = int(input())A = list(map(int, input().split()))dp = [ [ False ] * (total + 1) for i in range(N + 1) ]flag = [ [ -1 ] * (total + 1) for i in range(N + 1) ]dp[N][total] = Truefor i in range(N - 1, -1, -1):for j in range(0, total // A[i] + 1):if dp[i + 1][j * A[i]]:dp[i][j] = Trueflag[i][j] = 1for j in range(0, total - A[i] + 1):if dp[i + 1][j + A[i]]:dp[i][j] = Trueflag[i][j] = 0answer = ""pos, val = 1, A[0]while pos != N:if flag[pos][val] == 0:answer += '+'pos, val = pos + 1, val + A[pos]else:answer += '*'pos, val = pos + 1, val * A[pos]print(answer)