結果

問題 No.4 おもりと天秤
ユーザー あかりきあかりき
提出日時 2021-02-09 11:28:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 359 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 76,260 KB
最終ジャッジ日時 2023-09-20 21:44:14
合計ジャッジ時間 3,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,276 KB
testcase_01 AC 70 ms
71,572 KB
testcase_02 AC 80 ms
76,172 KB
testcase_03 AC 80 ms
75,944 KB
testcase_04 AC 77 ms
76,108 KB
testcase_05 AC 84 ms
76,096 KB
testcase_06 AC 73 ms
71,252 KB
testcase_07 AC 86 ms
76,204 KB
testcase_08 AC 70 ms
71,276 KB
testcase_09 AC 88 ms
76,236 KB
testcase_10 AC 87 ms
76,228 KB
testcase_11 AC 76 ms
76,044 KB
testcase_12 AC 70 ms
71,632 KB
testcase_13 AC 72 ms
71,444 KB
testcase_14 AC 73 ms
71,512 KB
testcase_15 AC 71 ms
71,296 KB
testcase_16 AC 77 ms
76,260 KB
testcase_17 AC 73 ms
71,420 KB
testcase_18 AC 85 ms
76,200 KB
testcase_19 AC 85 ms
75,984 KB
testcase_20 AC 85 ms
76,212 KB
testcase_21 AC 84 ms
76,200 KB
testcase_22 AC 84 ms
76,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
w=list(map(int,input().split()))
s=sum(w)
if s%2!=0:
  print('impossible')
  exit()
x=s//2
dp=[[0]*(x+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n):
  for j in range(x+1):
    dp[i+1][j]=dp[i][j]|dp[i+1][j]
    if j+w[i]<=x:
      dp[i+1][j+w[i]]=dp[i][j]|dp[i+1][j+w[i]]
if dp[-1][-1]==1:
  print('possible')
else:
  print('impossible')
0