結果

問題 No.10 +か×か
ユーザー szkhtsszkhts
提出日時 2020-10-10 11:36:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 813 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 18,428 KB
最終ジャッジ日時 2023-09-27 21:19:08
合計ジャッジ時間 7,444 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,960 KB
testcase_01 AC 21 ms
8,960 KB
testcase_02 AC 21 ms
8,996 KB
testcase_03 AC 613 ms
18,428 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def calculate(count, num, gross, op):
    if op == '+':
        if num + gross >= 100001:
            return
        dp[num + gross] = dp[gross] + '+'
        gross += num
    else:
        if num * gross >= 100001:
            return
        dp[num * gross] = dp[gross] + '*'
        gross *= num

    if count >= N - 1:
        return
    if dp[total] == '' or len(dp[total]) < N - 1:
        calculate(count + 1, nums[count + 1], gross, '+')
    if dp[total] == '' or len(dp[total]) < N - 1:
        calculate(count + 1, nums[count + 1], gross, '*')

N = int(input())
total = int(input())
nums = list(map(int, input().split()))
dp = ['' for i in range(100001)]

calculate(1, nums[1], nums[0], '+')
if dp[total] == '' or len(dp[total]) < N - 1:
    calculate(1, nums[1], nums[0], '*')
    
print(dp[total])
    
0