結果

問題 No.10 +か×か
ユーザー square1001square1001
提出日時 2022-02-17 11:23:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,381 ms / 5,000 ms
コード長 634 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 88,040 KB
最終ジャッジ日時 2023-09-11 17:31:15
合計ジャッジ時間 7,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,820 KB
testcase_01 AC 16 ms
7,876 KB
testcase_02 AC 15 ms
7,844 KB
testcase_03 AC 1,306 ms
88,040 KB
testcase_04 AC 1,381 ms
60,884 KB
testcase_05 AC 17 ms
7,736 KB
testcase_06 AC 1,338 ms
87,980 KB
testcase_07 AC 1,221 ms
60,904 KB
testcase_08 AC 310 ms
23,516 KB
testcase_09 AC 462 ms
36,976 KB
testcase_10 AC 23 ms
8,672 KB
testcase_11 AC 17 ms
8,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
total = int(input())
A = list(map(int, input().split()))

dp = [ [ False ] * (total + 1) for i in range(N + 1) ]
flag = [ [ -1 ] * (total + 1) for i in range(N + 1) ]
dp[N][total] = True
for i in range(N - 1, -1, -1):
	for j in range(0, total // A[i] + 1):
		if dp[i + 1][j * A[i]]:
			dp[i][j] = True
			flag[i][j] = 1
	for j in range(0, total - A[i] + 1):
		if dp[i + 1][j + A[i]]:
			dp[i][j] = True
			flag[i][j] = 0

answer = ""
pos, val = 1, A[0]
while pos != N:
	if flag[pos][val] == 0:
		answer += '+'
		pos, val = pos + 1, val + A[pos]
	else:
		answer += '*'
		pos, val = pos + 1, val * A[pos]

print(answer)
0