結果

問題 No.4 おもりと天秤
ユーザー shinshin
提出日時 2022-10-13 13:09:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,118 ms / 5,000 ms
コード長 472 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-26 12:00:16
合計ジャッジ時間 7,786 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = list(map(int , input().split()))

total = 0
for i in W:
  total += i

W.sort()
b = False

if total % 2 == 0:
  total //= 2
  sum = [0 , W[0]]
  for i in range(1 , N):
    sublist = []
    for s in sum:
      s += W[i]
      if s == total:
        b = True
        break
      elif not(s in sum) and s < total:
        sublist.append(s)
    if b:
      break
    sum += sublist
    sum.sort()
    
if b:
  print("possible")
else:
  print("impossible")
0