結果

問題 No.10 +か×か
ユーザー 👑 colognecologne
提出日時 2022-01-20 17:00:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 766 ms / 5,000 ms
コード長 1,009 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 363,520 KB
最終ジャッジ日時 2024-05-03 02:41:06
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,352 KB
testcase_01 AC 44 ms
51,968 KB
testcase_02 AC 40 ms
51,968 KB
testcase_03 AC 766 ms
363,520 KB
testcase_04 AC 112 ms
93,092 KB
testcase_05 AC 37 ms
52,652 KB
testcase_06 AC 763 ms
359,920 KB
testcase_07 AC 302 ms
175,684 KB
testcase_08 AC 108 ms
91,248 KB
testcase_09 AC 89 ms
83,968 KB
testcase_10 AC 40 ms
56,960 KB
testcase_11 AC 40 ms
57,088 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