結果

問題 No.4 おもりと天秤
ユーザー MitI_7MitI_7
提出日時 2017-05-10 20:31:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 487 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 8,012 KB
最終ジャッジ日時 2023-10-13 10:05:24
合計ジャッジ時間 1,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,860 KB
testcase_01 AC 16 ms
7,864 KB
testcase_02 AC 15 ms
7,820 KB
testcase_03 AC 15 ms
7,820 KB
testcase_04 AC 17 ms
7,784 KB
testcase_05 AC 47 ms
7,904 KB
testcase_06 AC 15 ms
7,752 KB
testcase_07 AC 47 ms
7,860 KB
testcase_08 AC 15 ms
7,752 KB
testcase_09 AC 32 ms
7,960 KB
testcase_10 AC 51 ms
7,924 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 15 ms
7,748 KB
testcase_14 WA -
testcase_15 AC 14 ms
7,892 KB
testcase_16 AC 15 ms
7,836 KB
testcase_17 AC 14 ms
7,860 KB
testcase_18 AC 33 ms
7,812 KB
testcase_19 AC 42 ms
7,776 KB
testcase_20 AC 44 ms
7,836 KB
testcase_21 AC 41 ms
7,832 KB
testcase_22 AC 42 ms
7,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, w_list):
    total = sum(w_list)
    if total % 2 != 0:
        return "impossible"

    k = total // 2
    dp = [False] * (k + 1)
    dp[0] = True
    for w in w_list:
        for i in range(len(dp)):
            if dp[i] and i + w < len(dp):
                dp[i + w] = True

    return "possible" if dp[k] else "impossible"


def main():
    n = int(input())
    w_list = list(map(int, input().split()))
    print(solve(n, w_list))


if __name__ == '__main__':
    main()
0