結果

問題 No.10 +か×か
ユーザー しらっ亭しらっ亭
提出日時 2015-06-20 01:47:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 12,564 KB
最終ジャッジ日時 2023-09-21 10:29:47
合計ジャッジ時間 7,188 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def solve(total, a):
    stack = [(total, len(a) - 1, [])]

    ans = []
    while stack:
        t, i, h = stack.pop()

        if i == 0:
            if t == a[0]:
                ans.append(h)
        else:
            if t % a[i] == 0:
                h2 = list(h)
                h2.append('*')
                stack.append((t // a[i], i - 1, h2))
            if t > a[i]:
                h2 = list(h)
                h2.append('+')
                stack.append((t - a[i], i - 1, h2))

    ans.sort()
    return ''.join(ans[-1][::-1])


def main():
    n = int(input())
    total = int(input())
    a = list(map(int, input().split()))

    print(solve(total, a))


if __name__ == '__main__':
    main()
0