結果

問題 No.4 おもりと天秤
ユーザー るさるさ
提出日時 2018-06-03 17:35:32
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 477 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-09-12 21:56:18
合計ジャッジ時間 2,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,220 KB
testcase_01 AC 18 ms
8,264 KB
testcase_02 AC 22 ms
8,348 KB
testcase_03 AC 20 ms
8,224 KB
testcase_04 AC 22 ms
8,428 KB
testcase_05 AC 162 ms
8,284 KB
testcase_06 AC 18 ms
8,404 KB
testcase_07 AC 168 ms
8,476 KB
testcase_08 AC 19 ms
8,368 KB
testcase_09 AC 284 ms
8,528 KB
testcase_10 AC 180 ms
8,336 KB
testcase_11 AC 19 ms
8,356 KB
testcase_12 AC 18 ms
8,224 KB
testcase_13 AC 18 ms
8,220 KB
testcase_14 AC 18 ms
8,236 KB
testcase_15 AC 17 ms
8,384 KB
testcase_16 AC 18 ms
8,408 KB
testcase_17 AC 18 ms
8,408 KB
testcase_18 AC 156 ms
8,292 KB
testcase_19 AC 149 ms
8,488 KB
testcase_20 AC 142 ms
8,276 KB
testcase_21 AC 140 ms
8,424 KB
testcase_22 AC 138 ms
8,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import copy
n=int(input())
w=list(map(int,input().split()))
hw=int(sum(w)/2)
if hw*2!=sum(w):
    print("impossible")
else:
    table=[0 for i in range(hw+1)]
    table[0]=1
    for i in w:
        ntable=copy(table)
        for j in range(hw+1):
            try:
                ntable[j+i]=max(table[j+i],table[j])
            except:
                pass
        table=copy(ntable)
    if table[-1]==1:
       print("possible")
    else:
       print("impossible")
0