結果

問題 No.10 +か×か
ユーザー titiatitia
提出日時 2021-11-02 01:33:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 896 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 820,936 KB
最終ジャッジ日時 2024-04-19 04:03:52
合計ジャッジ時間 6,044 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
T=int(input())
A=list(map(int,input().split()))

S=[0,A[0]]
for a in A[1:]:
    S.append(min(S[-1]+a,S[-1]*a))

def calc(i,T):
    #print(i,T)
    if i==last:
        if T in SET:
            for i in range(len(ANS)):
                if ANS[i]==T:
                    return bin(i)[2:].zfill(last)
        else:
            return -1
        
    if calc(i-1,T-A[i])!=-1:
        return calc(i-1,T-A[i])+"+"

    if T%A[i]==0 and T//A[i]>=S[i]:
        if calc(i-1,T//A[i])!=-1:
            return calc(i-1,T//A[i])+"*"
        
    return -1

ANS=[A[0]]
last=min(25,N-1)

for i in range(1,last+1):
    NANS=[]
    for ans in ANS:
        NANS.append(ans+A[i])
        NANS.append(ans*A[i])
    ANS=NANS

SET=set(ANS)
        
ANS=calc(N-1,T)

LANS=""
for ans in ANS:
    if ans=="0":
        LANS+="+"
    elif ans=="1":
        LANS+="*"
    else:
        LANS+=ans

print(LANS)
0