結果

問題 No.4 おもりと天秤
ユーザー asaka189asaka189
提出日時 2017-12-27 17:40:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 271 ms / 5,000 ms
コード長 574 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 12,344 KB
最終ジャッジ日時 2023-09-08 17:37:55
合計ジャッジ時間 2,493 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,876 KB
testcase_01 AC 15 ms
7,856 KB
testcase_02 AC 18 ms
8,296 KB
testcase_03 AC 18 ms
7,776 KB
testcase_04 AC 20 ms
8,224 KB
testcase_05 AC 119 ms
10,436 KB
testcase_06 AC 16 ms
7,780 KB
testcase_07 AC 121 ms
10,432 KB
testcase_08 AC 16 ms
7,840 KB
testcase_09 AC 271 ms
12,344 KB
testcase_10 AC 131 ms
10,820 KB
testcase_11 AC 16 ms
7,844 KB
testcase_12 AC 16 ms
7,780 KB
testcase_13 AC 15 ms
7,840 KB
testcase_14 AC 16 ms
7,800 KB
testcase_15 AC 15 ms
7,844 KB
testcase_16 AC 17 ms
7,804 KB
testcase_17 AC 16 ms
7,924 KB
testcase_18 AC 131 ms
10,540 KB
testcase_19 AC 111 ms
10,336 KB
testcase_20 AC 107 ms
10,224 KB
testcase_21 AC 103 ms
10,052 KB
testcase_22 AC 105 ms
10,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
w = list(map(int,input().split()))
tt = sum(w)
t = int(tt//2)
table = [[0 for i in range(t+1)] for k in range(n+1)]
for i in range(t+1):
	if i == 0:
		table[0][0] = True
	else:
		table[0][i] = False
if tt%2 != 0:
	print('impossible')
else:
	for i in range(1,n+1):
		for k in range(t+1):
			if table[i-1][k]:
				table[i][k]=table[i-1][k]
			elif w[i-1]<=k:
				if table[i-1][k-w[i-1]]:
					table[i][k]=table[i-1][k-w[i-1]]
				else:
					table[i][k] = False
			else:
				table[i][k] = False
	if table[n][t]:
		print('possible')
	else:
		print('impossible')
0