結果

問題 No.4 おもりと天秤
ユーザー pajannatpajannat
提出日時 2021-04-08 23:39:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 695 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 76,372 KB
最終ジャッジ日時 2023-09-06 07:22:52
合計ジャッジ時間 4,095 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,848 KB
testcase_01 AC 72 ms
71,460 KB
testcase_02 AC 76 ms
75,864 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 75 ms
75,836 KB
testcase_07 WA -
testcase_08 AC 71 ms
71,368 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 78 ms
75,900 KB
testcase_12 AC 75 ms
75,872 KB
testcase_13 AC 77 ms
75,928 KB
testcase_14 AC 75 ms
75,996 KB
testcase_15 AC 76 ms
76,112 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 88 ms
75,932 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = sorted([int(i) for i in input().split()])

dp = [[0]*(10000) for j in range(N)] # DPテーブルの作成

sum_W = sum(W)

if(sum_W % 2 == 1):
	print("impossible")
	exit()
	
for i in range(N):
	for j in range(10000):
		dp[i][j] = dp[i-1][j]	# i-1番目までにどの重さを作れたかをi番目の表にコピー
		if(dp[i][j] == 1):
			dp[i][j+W[i]] = 1	# これまでに作れた重さ+i番目のおもりの重さも作れる

	dp[i][W[i]] = 1				# i番目のおもりを使った重さは作れる
# 以上の操作でdp[N-1]に作れる重さの表が完成する

if(dp[N-1][int(sum_W/2)] == 1):
	print("possible")
else:
	print("impossible")
0