結果

問題 No.4 おもりと天秤
ユーザー ayame_pyayame_py
提出日時 2015-10-06 03:24:24
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,788 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 7,080 KB
実行使用メモリ 10,572 KB
最終ジャッジ日時 2023-09-08 16:27:50
合計ジャッジ時間 18,703 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
10,476 KB
testcase_01 AC 11 ms
5,868 KB
testcase_02 AC 288 ms
10,472 KB
testcase_03 AC 201 ms
10,392 KB
testcase_04 AC 279 ms
10,320 KB
testcase_05 AC 1,783 ms
10,420 KB
testcase_06 AC 64 ms
10,316 KB
testcase_07 AC 1,788 ms
10,404 KB
testcase_08 AC 10 ms
5,868 KB
testcase_09 AC 1,662 ms
10,524 KB
testcase_10 AC 1,787 ms
10,476 KB
testcase_11 AC 146 ms
10,372 KB
testcase_12 AC 79 ms
10,416 KB
testcase_13 AC 80 ms
10,388 KB
testcase_14 AC 97 ms
10,552 KB
testcase_15 AC 80 ms
10,416 KB
testcase_16 AC 161 ms
10,528 KB
testcase_17 AC 146 ms
10,552 KB
testcase_18 AC 1,714 ms
10,316 KB
testcase_19 AC 1,757 ms
10,572 KB
testcase_20 AC 1,756 ms
10,316 KB
testcase_21 AC 1,756 ms
10,320 KB
testcase_22 AC 1,768 ms
10,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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