結果

問題 No.10 +か×か
ユーザー ayaoniayaoni
提出日時 2020-12-04 10:13:56
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 328 ms / 5,000 ms
コード長 1,175 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 154,344 KB
最終ジャッジ日時 2023-08-21 06:32:40
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,200 KB
testcase_01 AC 70 ms
71,176 KB
testcase_02 AC 72 ms
71,140 KB
testcase_03 AC 328 ms
154,212 KB
testcase_04 AC 263 ms
127,388 KB
testcase_05 AC 71 ms
71,200 KB
testcase_06 AC 326 ms
154,344 KB
testcase_07 AC 258 ms
127,408 KB
testcase_08 AC 129 ms
91,104 KB
testcase_09 AC 166 ms
103,836 KB
testcase_10 AC 82 ms
76,312 KB
testcase_11 AC 79 ms
76,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
total = I()
A = LI()

dp0 = [[0]*(total+1) for _ in range(N)]
dp0[0][A[0]] = 1
for i in range(1,N):
    a = A[i]
    for j in range(1,total+1):
        if j >= a:
            dp0[i][j] |= dp0[i-1][j-a]
        if j % a == 0:
            dp0[i][j] |= dp0[i-1][j//a]

dp1 = [[0]*(total+1) for _ in range(N)]
dp1[-1][-1] = 1
for i in range(N-2,-1,-1):
    a = A[i+1]
    for j in range(1,total+1):
        if j+a <= total and dp1[i+1][j+a]:
            dp1[i][j] = 1
        elif j*a <= total and dp1[i+1][j*a]:
            dp1[i][j] = 1

ans = ''
x = A[0]
for i in range(1,N):
    a = A[i]
    if x+a <= total and dp1[i][x+a]:
        ans += '+'
        x += a
    else:
        ans += '*'
        x *= a

print(ans)
0