結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,868 KB
testcase_01 AC 72 ms
71,420 KB
testcase_02 AC 79 ms
75,988 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 78 ms
76,056 KB
testcase_07 WA -
testcase_08 AC 72 ms
71,528 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 80 ms
75,876 KB
testcase_12 AC 78 ms
75,940 KB
testcase_13 AC 79 ms
75,884 KB
testcase_14 AC 78 ms
75,932 KB
testcase_15 AC 78 ms
75,812 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 87 ms
75,868 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