結果

問題 No.4 おもりと天秤
ユーザー 定期定期
提出日時 2024-11-12 02:21:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 398 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-11-12 02:21:33
合計ジャッジ時間 4,186 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
weights = list(map(int, input().split()))

dp = [[False] * 10001 for _ in range(n+1)]
weight_sum = sum(weights)
if weight_sum & 1:
  print("impossible")
  exit()

dp[0][0] = True

for i in range(n):
  for j in range(10001):
    if dp[i][j]:
      dp[i + 1][j + weights[i]] = True
      dp[i + 1][j] = True

if dp[n][weight_sum // 2]:
  print("possible")
else:
  print("impossible")
0