結果

問題 No.4 おもりと天秤
ユーザー tmsausatmsausa
提出日時 2018-04-12 19:36:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 520 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 84,528 KB
最終ジャッジ日時 2023-09-09 04:25:23
合計ジャッジ時間 3,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,788 KB
testcase_01 AC 72 ms
71,436 KB
testcase_02 AC 82 ms
76,152 KB
testcase_03 AC 81 ms
76,008 KB
testcase_04 AC 84 ms
76,056 KB
testcase_05 AC 105 ms
84,404 KB
testcase_06 AC 77 ms
75,788 KB
testcase_07 AC 105 ms
84,444 KB
testcase_08 AC 72 ms
71,400 KB
testcase_09 AC 103 ms
84,288 KB
testcase_10 AC 104 ms
84,460 KB
testcase_11 AC 78 ms
76,048 KB
testcase_12 AC 77 ms
75,868 KB
testcase_13 AC 76 ms
76,052 KB
testcase_14 AC 77 ms
75,872 KB
testcase_15 AC 78 ms
76,064 KB
testcase_16 AC 79 ms
75,828 KB
testcase_17 AC 77 ms
75,824 KB
testcase_18 AC 103 ms
84,348 KB
testcase_19 AC 104 ms
84,404 KB
testcase_20 AC 105 ms
84,236 KB
testcase_21 AC 106 ms
84,528 KB
testcase_22 AC 101 ms
84,412 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] * (10001) for _ in range(N + 1)]

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

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