結果

問題 No.4 おもりと天秤
ユーザー tmsausatmsausa
提出日時 2018-04-12 19:42:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 76,208 KB
最終ジャッジ日時 2023-09-09 04:25:33
合計ジャッジ時間 3,232 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,944 KB
testcase_01 AC 72 ms
71,300 KB
testcase_02 AC 82 ms
76,200 KB
testcase_03 AC 83 ms
76,112 KB
testcase_04 AC 84 ms
76,184 KB
testcase_05 AC 89 ms
76,208 KB
testcase_06 AC 80 ms
75,612 KB
testcase_07 AC 91 ms
76,168 KB
testcase_08 AC 73 ms
71,088 KB
testcase_09 AC 88 ms
75,812 KB
testcase_10 AC 91 ms
76,192 KB
testcase_11 AC 80 ms
75,876 KB
testcase_12 AC 78 ms
76,072 KB
testcase_13 AC 79 ms
75,940 KB
testcase_14 AC 78 ms
76,000 KB
testcase_15 AC 78 ms
75,956 KB
testcase_16 AC 81 ms
75,932 KB
testcase_17 AC 79 ms
75,900 KB
testcase_18 AC 87 ms
76,036 KB
testcase_19 AC 89 ms
76,060 KB
testcase_20 AC 89 ms
76,016 KB
testcase_21 AC 90 ms
76,108 KB
testcase_22 AC 91 ms
75,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
weights_list = [0] + list(map(int, input().split(' ')))

total = sum(weights_list)
if total % 2 == 1:
    print("impossible")
    exit()

#dp = np.zeros((N + 1, 10001), dtype=np.bool)
dp = [0 for _ in range(10001)]

dp[0] = True
for i in range(1, N + 1):
    for j in range(10000, -1, -1):
        if (dp[j] == True) or ((j >= weights_list[i]) and (dp[j-weights_list[i]] == True)):
            dp[j] = True

if dp[total // 2]:
    print("possible")
else:
    print("impossible")
0