結果

問題 No.4 おもりと天秤
ユーザー 👑 KazunKazun
提出日時 2020-05-31 15:38:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 436 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 76,120 KB
最終ジャッジ日時 2023-08-11 02:41:13
合計ジャッジ時間 2,736 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,540 KB
testcase_01 AC 61 ms
71,064 KB
testcase_02 AC 68 ms
76,040 KB
testcase_03 AC 65 ms
76,020 KB
testcase_04 AC 68 ms
75,992 KB
testcase_05 AC 69 ms
76,104 KB
testcase_06 AC 58 ms
71,564 KB
testcase_07 AC 70 ms
75,828 KB
testcase_08 AC 59 ms
71,356 KB
testcase_09 AC 72 ms
76,056 KB
testcase_10 AC 72 ms
76,120 KB
testcase_11 AC 62 ms
76,000 KB
testcase_12 AC 61 ms
71,488 KB
testcase_13 AC 60 ms
71,160 KB
testcase_14 AC 59 ms
71,496 KB
testcase_15 AC 58 ms
71,300 KB
testcase_16 AC 65 ms
76,028 KB
testcase_17 AC 60 ms
71,324 KB
testcase_18 AC 70 ms
76,056 KB
testcase_19 AC 70 ms
76,076 KB
testcase_20 AC 70 ms
76,112 KB
testcase_21 AC 70 ms
75,692 KB
testcase_22 AC 72 ms
75,920 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