結果

問題 No.4 おもりと天秤
ユーザー pluto77
提出日時 2016-03-02 11:25:40
言語 Python2
(2.7.18)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 465 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-06-26 09:26:42
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
##yuki_4
import sys

def ssum(s,k):
 dp[0]=True
 for i in xrange(len(s)):
  for j in xrange(k,-1,-1):
   if dp[j]==True and j+s[i]<=k:
    dp[j+s[i]]=True
 if dp[k]:
  return True
 return False

n=int(raw_input())
s=map(int,raw_input().split())

sum=0
for i in xrange(len(s)):
 sum+=s[i]

if sum%2==1:
 print "impossible"
 sys.exit()

k=sum/2
dp=[False for i in xrange(n*k+1)]

res=ssum(s,k)
if res==True:
 print "possible"
else:
 print "impossible"
0