結果

問題 No.4 おもりと天秤
ユーザー goto_isyukugoto_isyuku
提出日時 2017-05-29 13:28:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,171 ms / 5,000 ms
コード長 518 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 53,596 KB
最終ジャッジ日時 2023-10-21 16:52:51
合計ジャッジ時間 18,383 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 457 ms
42,396 KB
testcase_01 AC 458 ms
42,396 KB
testcase_02 AC 464 ms
42,396 KB
testcase_03 AC 463 ms
42,396 KB
testcase_04 AC 474 ms
42,396 KB
testcase_05 AC 1,134 ms
53,596 KB
testcase_06 AC 454 ms
42,396 KB
testcase_07 AC 1,157 ms
53,596 KB
testcase_08 AC 461 ms
42,396 KB
testcase_09 AC 965 ms
53,596 KB
testcase_10 AC 1,171 ms
53,596 KB
testcase_11 AC 459 ms
42,396 KB
testcase_12 AC 454 ms
42,396 KB
testcase_13 AC 453 ms
42,396 KB
testcase_14 AC 456 ms
42,396 KB
testcase_15 AC 455 ms
42,396 KB
testcase_16 AC 465 ms
42,396 KB
testcase_17 AC 467 ms
42,396 KB
testcase_18 AC 1,052 ms
53,596 KB
testcase_19 AC 1,138 ms
53,596 KB
testcase_20 AC 1,130 ms
53,596 KB
testcase_21 AC 1,114 ms
53,596 KB
testcase_22 AC 1,143 ms
53,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

n = int(input())
wl = [int(x) for x in input().split()]

if sum(wl) % 2 == 1:
    print("impossible")
else:

    dp = np.array([[0 for x in range(n * 100 + 1)] for y in range(n + 1)])
    
    for i in range(n + 1):
        dp[i][0] = 1
    
    for i in range(n):
        for j in range(n * 100):
            if dp[i][j] == 1:
                dp[i + 1][j] = 1
                dp[i + 1][j + wl[i]] = 1
    if dp[n][sum(wl) // 2] == 1:
        print("possible")
    else:
        print("impossible")
0