結果

問題 No.4 おもりと天秤
ユーザー warashi
提出日時 2015-02-09 20:38:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 600 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 124,572 KB
最終ジャッジ日時 2024-06-23 16:32:44
合計ジャッジ時間 7,093 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

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