結果

問題 No.4 おもりと天秤
ユーザー gahougahou
提出日時 2016-11-01 17:37:30
言語 Python2
(2.7.18)
結果
AC  
実行時間 445 ms / 5,000 ms
コード長 384 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 6,504 KB
実行使用メモリ 13,852 KB
最終ジャッジ日時 2023-09-08 17:13:48
合計ジャッジ時間 6,371 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
6,276 KB
testcase_01 AC 33 ms
6,416 KB
testcase_02 AC 77 ms
7,064 KB
testcase_03 AC 55 ms
6,608 KB
testcase_04 AC 76 ms
7,160 KB
testcase_05 AC 404 ms
13,832 KB
testcase_06 AC 20 ms
6,164 KB
testcase_07 AC 408 ms
13,852 KB
testcase_08 AC 442 ms
13,680 KB
testcase_09 AC 445 ms
13,752 KB
testcase_10 AC 396 ms
13,844 KB
testcase_11 AC 43 ms
6,544 KB
testcase_12 AC 25 ms
6,264 KB
testcase_13 AC 24 ms
6,220 KB
testcase_14 AC 30 ms
6,316 KB
testcase_15 AC 25 ms
6,080 KB
testcase_16 AC 46 ms
6,520 KB
testcase_17 AC 42 ms
6,404 KB
testcase_18 AC 424 ms
13,636 KB
testcase_19 AC 408 ms
13,712 KB
testcase_20 AC 406 ms
13,708 KB
testcase_21 AC 414 ms
13,832 KB
testcase_22 AC 410 ms
13,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(raw_input())
w=map(int,raw_input().split())
dp=[[False]*(10**4+1) for _ in xrange(n+1)]
dp[0][0] = True
su=0
for i in xrange(1,n+1):
  su+=w[i-1]
  for j in xrange(10**4+1):
    if j-w[i-1]<0:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = dp[i-1][j] or dp[i-1][j-w[i-1]]
if su%2==1: print "impossible"
else:
  if dp[n][su/2]: print "possible"
  else: print "impossible"
0