結果

問題 No.4 おもりと天秤
ユーザー dashi_dragonsdashi_dragons
提出日時 2017-02-14 18:29:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 754 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,168 KB
最終ジャッジ日時 2023-08-28 16:52:02
合計ジャッジ時間 1,570 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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.reverse()

while True:
	buf = 0
	cnt = 0
	flag = True
	
	for i in range(0,len(list)):
		buf += W[i] * list[i]
		if buf > median:
			flag = False
			break

	if buf not in ans and flag == True:
		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