結果

問題 No.4 おもりと天秤
ユーザー rarpipipirarpipipi
提出日時 2023-12-31 03:52:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 411 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 69,916 KB
最終ジャッジ日時 2023-12-31 03:52:43
合計ジャッジ時間 2,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 49 ms
61,720 KB
testcase_03 AC 42 ms
59,516 KB
testcase_04 AC 44 ms
61,720 KB
testcase_05 AC 57 ms
67,904 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 58 ms
67,904 KB
testcase_08 AC 46 ms
61,720 KB
testcase_09 AC 63 ms
69,916 KB
testcase_10 AC 59 ms
67,896 KB
testcase_11 AC 46 ms
59,388 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 AC 35 ms
53,460 KB
testcase_14 AC 39 ms
57,300 KB
testcase_15 AC 36 ms
53,460 KB
testcase_16 AC 44 ms
59,388 KB
testcase_17 AC 35 ms
53,460 KB
testcase_18 AC 55 ms
67,908 KB
testcase_19 AC 56 ms
67,912 KB
testcase_20 AC 56 ms
67,912 KB
testcase_21 AC 57 ms
67,912 KB
testcase_22 AC 57 ms
67,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
n=int(input())
w=list(map(int,input().split()))
mid=-(-sum(w)//2)

dp=[[0]*2*(mid+1) for i in range(n+1)]
dp[-1][0]=1
for i in range(n):
    for ind in range(-mid,mid+1):
        if not dp[i-1][ind]:continue
        if ind+w[i]<=mid:
            dp[i][ind+w[i]]=1
        if -mid<=ind-w[i]:
            dp[i][ind-w[i]]=1

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