結果

問題 No.4 おもりと天秤
ユーザー dashi_dragonsdashi_dragons
提出日時 2017-02-14 18:22:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 672 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,720 KB
実行使用メモリ 12,636 KB
最終ジャッジ日時 2023-08-28 16:51:51
合計ジャッジ時間 7,377 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,160 KB
testcase_01 AC 16 ms
8,204 KB
testcase_02 AC 238 ms
7,700 KB
testcase_03 AC 21 ms
7,884 KB
testcase_04 AC 295 ms
7,860 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N = int(input())
W = input().split(' ')
median = 0
list = []
ans = []

for i in range(0,len(W)):
	W[i] = int(W[i])
	median += W[i]
	list.append(0)

if median % 2 == 1:
	print('impossible')
	sys.exit()

median = median // 2

W.sort()

while True:
	buf = 0
	cnt = 0
	
	for i in range(0,len(list)):
		buf += W[i] * list[i]

	if buf not in ans:
		ans.append(buf)

	while True:		
		if len(list) > 0:
			cnt += 1
			buf = list.pop()
			
			if buf != 1:
				break
			
		else:
			break
	if cnt == N and buf == 1:
		break
	
	list.append(1)
	cnt -= 1

	for i in range(0,cnt):
		list.append(0)

#print(ans)

if median in ans:
	print('possible')
else:
	print('impossible')
0