結果

問題 No.4 おもりと天秤
ユーザー tobusakanatobusakana
提出日時 2020-11-29 19:01:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 455 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 76,296 KB
最終ジャッジ日時 2023-10-11 02:31:29
合計ジャッジ時間 3,638 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,356 KB
testcase_01 AC 74 ms
71,340 KB
testcase_02 AC 76 ms
75,832 KB
testcase_03 AC 75 ms
75,972 KB
testcase_04 AC 77 ms
76,076 KB
testcase_05 AC 82 ms
76,224 KB
testcase_06 AC 72 ms
71,300 KB
testcase_07 AC 82 ms
76,200 KB
testcase_08 AC 71 ms
71,304 KB
testcase_09 AC 79 ms
75,972 KB
testcase_10 AC 82 ms
76,068 KB
testcase_11 AC 77 ms
75,528 KB
testcase_12 AC 74 ms
71,376 KB
testcase_13 AC 73 ms
71,572 KB
testcase_14 AC 73 ms
71,296 KB
testcase_15 AC 72 ms
71,348 KB
testcase_16 AC 75 ms
75,944 KB
testcase_17 AC 72 ms
71,576 KB
testcase_18 AC 79 ms
76,040 KB
testcase_19 AC 80 ms
76,296 KB
testcase_20 AC 81 ms
76,184 KB
testcase_21 AC 80 ms
76,188 KB
testcase_22 AC 81 ms
76,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

# 総和//2を作れるかを判定

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

all = sum(W)
if all % 2 == 1:
  print("impossible")
  exit(0)
  
A = all // 2
dp = [False] * (A + 1)
dp[0] = True

for i in range(len(W)):
  for j in range(len(dp) - 1, -1, -1):
    if not dp[j]:
      continue
    if j + W[i] <= A:
      dp[j + W[i]] = True

if dp[A]:
  print("possible")
else:
  print("impossible")
0