結果

問題 No.4 おもりと天秤
ユーザー hiyokko2hiyokko2
提出日時 2016-07-29 20:38:55
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 17,040 KB
最終ジャッジ日時 2023-09-08 16:47:38
合計ジャッジ時間 1,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,948 KB
testcase_01 AC 15 ms
7,820 KB
testcase_02 AC 17 ms
8,420 KB
testcase_03 AC 15 ms
7,992 KB
testcase_04 AC 15 ms
7,940 KB
testcase_05 AC 55 ms
12,232 KB
testcase_06 AC 15 ms
7,900 KB
testcase_07 AC 60 ms
12,716 KB
testcase_08 AC 18 ms
8,300 KB
testcase_09 AC 16 ms
8,264 KB
testcase_10 AC 65 ms
13,652 KB
testcase_11 AC 15 ms
7,784 KB
testcase_12 AC 15 ms
7,800 KB
testcase_13 AC 15 ms
7,792 KB
testcase_14 AC 15 ms
7,804 KB
testcase_15 AC 15 ms
7,808 KB
testcase_16 AC 15 ms
7,796 KB
testcase_17 AC 15 ms
7,844 KB
testcase_18 AC 107 ms
17,040 KB
testcase_19 AC 52 ms
12,292 KB
testcase_20 AC 50 ms
12,204 KB
testcase_21 AC 50 ms
12,072 KB
testcase_22 AC 57 ms
12,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def rec(i, j):
	#if dp[i][j] != -1:
	#	return dp[i][j]
	if i in dphash and j in dphash[i]:
		return dphash[i][j]
	if i == N:
		if j == 0:
			ret = True
		else:
			ret = False
	else:
		ret = rec(i + 1, j + W[i]) or rec(i + 1, j - W[i])
	if i in dphash:
		dphash[i][j] = ret
	else:
		dphash[i] = {}
		dphash[i][j] = ret
	return ret

N = int(input())
W = list(map(int, input().split()))
#dp = [[-1 for j in range(10001)] for i in range(101)]
dphash = {}
if rec(0, 0):
	print("possible")
else:
	print("impossible")
0