結果

問題 No.4 おもりと天秤
ユーザー ayaoniayaoni
提出日時 2020-12-04 07:09:23
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 775 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 76,192 KB
最終ジャッジ日時 2023-10-12 18:53:33
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,088 KB
testcase_01 AC 73 ms
71,188 KB
testcase_02 AC 82 ms
75,964 KB
testcase_03 AC 77 ms
75,912 KB
testcase_04 AC 82 ms
76,064 KB
testcase_05 AC 81 ms
76,132 KB
testcase_06 AC 72 ms
71,248 KB
testcase_07 AC 82 ms
76,192 KB
testcase_08 AC 72 ms
71,200 KB
testcase_09 AC 83 ms
75,956 KB
testcase_10 AC 81 ms
76,152 KB
testcase_11 AC 76 ms
75,836 KB
testcase_12 AC 71 ms
71,360 KB
testcase_13 AC 72 ms
71,216 KB
testcase_14 AC 73 ms
71,352 KB
testcase_15 AC 72 ms
71,360 KB
testcase_16 AC 78 ms
75,900 KB
testcase_17 AC 72 ms
71,352 KB
testcase_18 AC 82 ms
75,864 KB
testcase_19 AC 82 ms
75,932 KB
testcase_20 AC 81 ms
76,056 KB
testcase_21 AC 82 ms
76,012 KB
testcase_22 AC 82 ms
75,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
W = [0]+LI()

s = sum(W)
if s % 2 == 1:
    print('impossible')
    exit()

X = s//2
dp = [[0]*(X+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    w = W[i]
    for j in range(X+1):
        if j >= w:
            dp[i][j] = dp[i-1][j] | dp[i-1][j-w]

print('possible' if dp[-1][-1] else 'impossible')
0