結果

問題 No.4 おもりと天秤
コンテスト
ユーザー silversmith
提出日時 2019-05-03 19:40:52
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 517 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 278 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2026-10-09 23:51:30
合計ジャッジ時間 13,565 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

c_idx = 10 ** 5
dp = [False] * (2 * c_idx)
dp[c_idx + W[0]] = True
dp[c_idx - W[0]] = True
dp2 = [False] * len(dp)
for i in range(N -1):
    for x in range(2* c_idx):
        if x < W[i+1]:
            dp2[x] = dp[x + W[i+1]]
        elif x + W[i+1] > len(dp) -1:
            dp2[x] = dp[x - W[i+1]]
        else:
            dp2[x] = dp[x + W[i+1]] or dp[x - W[i+1]]
    dp, dp2 = dp2, dp

if dp[c_idx] == True:
    print('possible')
else:
    print('impossible')
0