結果

問題 No.10 +か×か
ユーザー titiatitia
提出日時 2021-11-02 01:35:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 115,244 KB
最終ジャッジ日時 2024-04-19 04:08:51
合計ジャッジ時間 5,203 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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))

from functools import lru_cache
@lru_cache(maxsize=None)
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(20,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