結果

問題 No.10 +か×か
ユーザー bionesbiones
提出日時 2015-09-15 12:30:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 591 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 12,608 KB
最終ジャッジ日時 2023-09-26 12:02:51
合計ジャッジ時間 8,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def f(k):
    global nums,sum,flags

    if sum>total:
        return False
    if sum==total and len(flags)==(N-1):
        s=""
        for fl in flags:
            s+=fl

        print(s)
        exit()

    if k>=N-1:
        return


    sum+=nums[k+1]
    flags.append("+")
    f(k+1)
    flags.pop()
    sum-=nums[k+1]

    hoge=sum
    sum=sum*nums[k+1]
    flags.append("*")
    f(k+1)
    flags.pop()
    sum=hoge



'''
N=4
total=31
nums=list(map(int,"1 2 10 1".split(" ")))
'''

N=int(input())
total=int(input())
nums=list(map(int,input().split(" ")))

flags=[]
sum=nums[0]
f(0)
0