結果

問題 No.4 おもりと天秤
ユーザー mtkmtk
提出日時 2018-12-25 14:28:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 273 ms / 5,000 ms
コード長 406 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-04-08 22:22:55
合計ジャッジ時間 2,847 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,112 KB
testcase_01 AC 31 ms
10,112 KB
testcase_02 AC 33 ms
10,112 KB
testcase_03 AC 31 ms
10,112 KB
testcase_04 AC 32 ms
10,112 KB
testcase_05 AC 137 ms
12,032 KB
testcase_06 AC 30 ms
10,112 KB
testcase_07 AC 137 ms
12,032 KB
testcase_08 AC 30 ms
10,112 KB
testcase_09 AC 273 ms
13,824 KB
testcase_10 AC 153 ms
12,288 KB
testcase_11 AC 29 ms
10,112 KB
testcase_12 AC 29 ms
10,112 KB
testcase_13 AC 29 ms
10,112 KB
testcase_14 AC 32 ms
10,112 KB
testcase_15 AC 29 ms
10,112 KB
testcase_16 AC 30 ms
10,112 KB
testcase_17 AC 29 ms
10,112 KB
testcase_18 AC 148 ms
12,032 KB
testcase_19 AC 131 ms
11,904 KB
testcase_20 AC 126 ms
11,904 KB
testcase_21 AC 120 ms
11,776 KB
testcase_22 AC 125 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
Ws=list(map(int,input().split()))
if sum(Ws)%2==1:
    print('impossible')
    exit()
W=sum(Ws)//2
dp =[[0]*(W+1) for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
    for w in range(W+1):
        if w >= Ws[i-1]:
            dp[i][w] = dp[i-1][w-Ws[i-1]] or dp[i-1][w]
        else:
            dp[i][w] = dp[i-1][w]

if dp[N][W]==1:
    print('possible')
else:
    print('impossible')
0