結果

問題 No.4 おもりと天秤
コンテスト
ユーザー konchanksu
提出日時 2020-04-27 14:57:18
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 446 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 357 ms
コンパイル使用メモリ 20,792 KB
実行使用メモリ 15,372 KB
最終ジャッジ日時 2026-05-15 21:30:31
合計ジャッジ時間 4,503 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

if full % 2 == 1:
    print('impossible')
    exit()

dp = [-1 for i in range(full + 1)]
half = full // 2
dp[half] = 0

for i in range(N):
    for j in range(full):
        if dp[j] == i:
            if j + W[i] <= full:
                dp[j + W[i]] = i + 1
            if j - W[i] >= 0:
                dp[j - W[i]] = i + 1

print('possible' if dp[half] == N else 'impossible')
0