結果

問題 No.4 おもりと天秤
ユーザー elsyelsy
提出日時 2023-11-17 15:16:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 400 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 70,204 KB
最終ジャッジ日時 2023-11-17 15:16:43
合計ジャッジ時間 2,482 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 44 ms
61,864 KB
testcase_03 AC 42 ms
59,764 KB
testcase_04 AC 44 ms
61,988 KB
testcase_05 AC 56 ms
66,092 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 58 ms
66,092 KB
testcase_08 AC 44 ms
61,864 KB
testcase_09 AC 62 ms
70,204 KB
testcase_10 AC 57 ms
66,080 KB
testcase_11 AC 41 ms
59,768 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 49 ms
53,460 KB
testcase_14 AC 41 ms
59,640 KB
testcase_15 AC 36 ms
53,460 KB
testcase_16 AC 41 ms
59,640 KB
testcase_17 AC 36 ms
53,460 KB
testcase_18 AC 54 ms
66,108 KB
testcase_19 AC 55 ms
66,108 KB
testcase_20 AC 55 ms
66,108 KB
testcase_21 AC 54 ms
66,116 KB
testcase_22 AC 55 ms
66,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [0] + list(map(int,input().split()))
w = sum(A)
dp = [[False for _ in range(w + 1)] for _ in range(n + 1)]
dp[0][0] = True
for i in range(1,n + 1):
	for j in range(1,w + 1):
		if j - A[i] >= 0:
			dp[i][j] = dp[i - 1][j - A[i]] or dp[i - 1][j]
		else:
			dp[i][j] = dp[i - 1][j]
if w % 2 == 1:
	print("impossible")
elif dp[n][w//2]:
	print("possible")
else:
	print("impossible")
0