結果

問題 No.4 おもりと天秤
ユーザー warashiwarashi
提出日時 2015-02-09 20:43:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 640 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 140,952 KB
最終ジャッジ日時 2023-09-05 21:13:05
合計ジャッジ時間 7,759 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,800 KB
testcase_01 AC 16 ms
8,128 KB
testcase_02 AC 111 ms
11,284 KB
testcase_03 AC 17 ms
7,796 KB
testcase_04 AC 17 ms
7,796 KB
testcase_05 AC 25 ms
8,724 KB
testcase_06 AC 17 ms
7,852 KB
testcase_07 AC 29 ms
8,932 KB
testcase_08 AC 17 ms
8,008 KB
testcase_09 AC 16 ms
7,820 KB
testcase_10 AC 107 ms
11,588 KB
testcase_11 AC 17 ms
7,864 KB
testcase_12 AC 16 ms
7,744 KB
testcase_13 AC 16 ms
7,796 KB
testcase_14 AC 16 ms
7,852 KB
testcase_15 AC 16 ms
7,852 KB
testcase_16 AC 16 ms
7,748 KB
testcase_17 AC 16 ms
7,804 KB
testcase_18 TLE -
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 False
    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