結果

問題 No.10 +か×か
ユーザー 👑 colognecologne
提出日時 2022-01-20 17:00:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 772 ms / 5,000 ms
コード長 1,009 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 381,872 KB
最終ジャッジ日時 2023-08-15 15:22:36
合計ジャッジ時間 4,066 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,184 KB
testcase_01 AC 71 ms
70,992 KB
testcase_02 AC 71 ms
70,948 KB
testcase_03 AC 772 ms
381,872 KB
testcase_04 AC 143 ms
101,468 KB
testcase_05 AC 70 ms
71,240 KB
testcase_06 AC 764 ms
377,864 KB
testcase_07 AC 315 ms
175,332 KB
testcase_08 AC 132 ms
89,272 KB
testcase_09 AC 119 ms
89,264 KB
testcase_10 AC 73 ms
74,852 KB
testcase_11 AC 74 ms
74,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline


def main():
    N = int(input())
    Total = int(input())
    *A, = map(int, input().split())

    DP = [[None]*(Total+1) for i in range(N)]
    DP[0][A[0]] = ''

    for step in range(1, N):
        for i in range(Total+1):
            if DP[step-1][i] is not None:
                if i * A[step] <= Total:
                    if DP[step][i * A[step]] is None:
                        DP[step][i * A[step]] = DP[step-1][i] + '*'
                    else:
                        DP[step][i * A[step]
                                 ] = max(DP[step][i * A[step]], DP[step-1][i] + '*')
                if i + A[step] <= Total:
                    if DP[step][i + A[step]] is None:
                        DP[step][i + A[step]] = DP[step-1][i] + '+'
                    else:
                        DP[step][i + A[step]
                                 ] = max(DP[step][i + A[step]], DP[step-1][i] + '+')

    print(DP[-1][-1])


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