結果

問題 No.4 おもりと天秤
ユーザー warashiwarashi
提出日時 2015-02-09 20:38:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 600 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 12,228 KB
最終ジャッジ日時 2023-09-05 21:10:11
合計ジャッジ時間 7,143 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,940 KB
testcase_01 AC 17 ms
8,144 KB
testcase_02 AC 169 ms
12,228 KB
testcase_03 AC 18 ms
7,864 KB
testcase_04 AC 20 ms
8,228 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


def memoize(f):
    table = {}

    def func(*args):
        if args not in table:
            table[args] = f(*args)
        return table[args]
    return func


@memoize
def ok(weight, rest):
    if weight == 0:
        return True
    for w in rest:
        r = list(rest)
        r.remove(w)
        if ok(weight - w, tuple(sorted(r))):
            return True
    return False

N = int(input())
W = [int(x) for x in input().split()]
if sum(W) % 2 == 1:
    print("impossible")
    exit()
if ok(sum(W) // 2, tuple(W)):
    print("possible")
else:
    print("impossible")
0