結果

問題 No.4 おもりと天秤
コンテスト
ユーザー ayame_py
提出日時 2015-10-06 03:24:24
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 91 ms / 5,000 ms
+ 476µs
コード長 533 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 62 ms
コンパイル使用メモリ 81,588 KB
実行使用メモリ 84,608 KB
最終ジャッジ日時 2026-07-17 22:03:15
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# coding: utf-8
import sys
maxW = 100001
N = int(raw_input())
W = map(int, raw_input().split())

#重さの合計が奇数なら終了!
sumW = sum(W)
if sumW % 2 == 1:
    print 'impossible'
    sys.exit()

dp = [[False for _ in range(maxW)] for _ in range(2)]
dp[0][0] = True
c = 0
for weight in W:
    for i in range(maxW):
        if dp[c%2][i]== True:
            dp[(c+1)%2][i] = True
            if i+weight < maxW: dp[(c+1)%2][i+weight] = True
    c+=1

if dp[c%2][sumW/2]:
    print 'possible'
else:
    print 'impossible'
0