結果
問題 | No.10 +か×か |
ユーザー | konchanksu |
提出日時 | 2020-04-16 20:41:51 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 3,435 ms / 5,000 ms |
コード長 | 1,001 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 11,084 KB |
実行使用メモリ | 295,864 KB |
最終ジャッジ日時 | 2023-08-21 06:29:46 |
合計ジャッジ時間 | 9,936 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,264 KB |
testcase_01 | AC | 17 ms
8,232 KB |
testcase_02 | AC | 17 ms
8,360 KB |
testcase_03 | AC | 3,435 ms
295,864 KB |
testcase_04 | AC | 198 ms
36,856 KB |
testcase_05 | AC | 16 ms
8,284 KB |
testcase_06 | AC | 3,377 ms
293,712 KB |
testcase_07 | AC | 1,268 ms
107,416 KB |
testcase_08 | AC | 280 ms
28,264 KB |
testcase_09 | AC | 327 ms
30,096 KB |
testcase_10 | AC | 18 ms
8,540 KB |
testcase_11 | AC | 16 ms
8,228 KB |
ソースコード
n = int(input()) total = int(input()) a = list(map(int, input().split())) dp = [['' for i in range(total + 1)] for j in range(n + 1)] if total >= a[0] * a[1]: dp[2][a[0] * a[1]] = '*' if total >= a[0] + a[1]: dp[2][a[0] + a[1]] = '+' tmp = max(a[0] + a[1], a[0] * a[1]) for i in range(2, n): tmp = max(tmp * a[i], tmp + a[i]) for j in range(1, min(tmp + 1, total) + 1): if dp[i][j] != '': if j * a[i] <= total: if dp[i + 1][j * a[i]] != '': if dp[i][j] + '*' > dp[i + 1][j * a[i]]: dp[i + 1][j * a[i]] = dp[i][j] + '*' else: dp[i + 1][j * a[i]] = dp[i][j] + '*' if j + a[i] <= total: if dp[i + 1][j + a[i]] != '': if dp[i][j] + '+' > dp[i + 1][j + a[i]]: dp[i + 1][j + a[i]] = dp[i][j] + '+' else: dp[i + 1][j + a[i]] = dp[i][j] + '+' print(dp[n][total])