結果

問題 No.4 おもりと天秤
ユーザー ireenaireena
提出日時 2022-01-22 15:11:26
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 323 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 76,224 KB
最終ジャッジ日時 2023-08-18 08:31:48
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,480 KB
testcase_01 AC 73 ms
71,516 KB
testcase_02 AC 77 ms
75,984 KB
testcase_03 AC 76 ms
75,856 KB
testcase_04 AC 79 ms
76,152 KB
testcase_05 AC 82 ms
76,016 KB
testcase_06 AC 73 ms
71,480 KB
testcase_07 AC 84 ms
75,976 KB
testcase_08 AC 74 ms
71,376 KB
testcase_09 AC 79 ms
75,940 KB
testcase_10 AC 83 ms
76,064 KB
testcase_11 AC 73 ms
71,480 KB
testcase_12 AC 71 ms
71,500 KB
testcase_13 AC 73 ms
71,424 KB
testcase_14 AC 74 ms
71,192 KB
testcase_15 AC 72 ms
71,320 KB
testcase_16 AC 73 ms
71,324 KB
testcase_17 AC 72 ms
71,284 KB
testcase_18 AC 82 ms
76,020 KB
testcase_19 AC 82 ms
76,088 KB
testcase_20 AC 84 ms
76,224 KB
testcase_21 AC 82 ms
76,048 KB
testcase_22 AC 83 ms
76,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = list(map(int, input().split()))

sumW = sum(W)

if sumW & 1:
    print("impossible")
    exit()

s2 = sumW //2
dp = [False] * (s2 + 1)
dp[0] = True

for w in W:
    for i in range(s2+1)[::-1]:
        if i-w < 0:
            break
        dp[i] |= dp[i-w]

print("possible" if dp[s2] else "impossible")
0