結果

問題 No.10 +か×か
ユーザー bionesbiones
提出日時 2015-09-15 15:57:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 935 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 93,340 KB
最終ジャッジ日時 2023-09-26 12:03:33
合計ジャッジ時間 12,877 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,612 KB
testcase_01 AC 73 ms
71,556 KB
testcase_02 AC 69 ms
71,372 KB
testcase_03 TLE -
testcase_04 AC 118 ms
77,680 KB
testcase_05 AC 72 ms
71,308 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    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


    '''
    print(dp)
    print(sum)
    input()
    '''
    if not(sum in dp[k]):

        dp[k].append(sum)
        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

    #print(flags)


'''
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=[]
dp=[[]for i in range(N)]
'''
import numpy as np
asum=[0]*N
aprod=[0]*N
for i in range(len(nums)):
    asum[i]=np.sum(nums[i::])
    aprod[i]=np.product(nums[i::])

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