結果

問題 No.10 +か×か
ユーザー tktk_snsntktk_snsn
提出日時 2021-10-26 23:22:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 551 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 17,692 KB
最終ジャッジ日時 2024-04-15 23:14:53
合計ジャッジ時間 7,420 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 289 ms
10,880 KB
testcase_04 TLE -
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()))
tmp = []


def dfs(i, val):
    if i == N:
        if val == T:
            ans = "".join(tmp)
            print(ans.replace("0", "+").replace("1", "*"))
            return True
        return False

    if val + A[i] <= T:
        tmp.append("0")
        if dfs(i + 1, val + A[i]):
            return True
        tmp.pop()
    if val * A[i] <= T:
        tmp.append("1")
        if dfs(i + 1, val * A[i]):
            return True
        tmp.pop()
    return False


dfs(1, A[0])
0