結果

問題 No.4 おもりと天秤
ユーザー 👑 KazunKazun
提出日時 2020-05-31 15:38:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 436 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 64,256 KB
最終ジャッジ日時 2024-04-28 19:47:36
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,968 KB
testcase_01 AC 41 ms
51,584 KB
testcase_02 AC 50 ms
59,648 KB
testcase_03 AC 48 ms
58,752 KB
testcase_04 AC 50 ms
59,776 KB
testcase_05 AC 58 ms
63,232 KB
testcase_06 AC 40 ms
51,840 KB
testcase_07 AC 58 ms
62,976 KB
testcase_08 AC 41 ms
51,712 KB
testcase_09 AC 60 ms
64,256 KB
testcase_10 AC 58 ms
63,360 KB
testcase_11 AC 46 ms
57,984 KB
testcase_12 AC 40 ms
51,712 KB
testcase_13 AC 41 ms
51,712 KB
testcase_14 AC 41 ms
51,968 KB
testcase_15 AC 40 ms
51,840 KB
testcase_16 AC 48 ms
58,752 KB
testcase_17 AC 40 ms
51,712 KB
testcase_18 AC 59 ms
62,976 KB
testcase_19 AC 61 ms
62,848 KB
testcase_20 AC 60 ms
62,848 KB
testcase_21 AC 58 ms
62,848 KB
testcase_22 AC 58 ms
62,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if sum(W)%2:
    print("impossible")
else:
    T=sum(W)//2
    A=[[0]*(T+1) for _ in range(N+1)]
    
    A[0][0]=1

    for k in range(1,N+1):
        for w in range(T+1):
            if w<W[k-1]:
                A[k][w]=A[k-1][w]
            else:
                A[k][w]=max(A[k-1][w],A[k-1][w-W[k-1]])

    if A[N][T]:
        print("possible")
    else:
        print("impossible")
0