結果

問題 No.4 おもりと天秤
ユーザー phantomilephantomile
提出日時 2015-12-19 08:40:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 9,192 KB
最終ジャッジ日時 2023-09-08 16:30:02
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,484 KB
testcase_01 AC 19 ms
8,504 KB
testcase_02 AC 19 ms
8,516 KB
testcase_03 AC 19 ms
8,496 KB
testcase_04 AC 19 ms
8,700 KB
testcase_05 AC 54 ms
8,988 KB
testcase_06 AC 19 ms
8,560 KB
testcase_07 AC 58 ms
8,876 KB
testcase_08 AC 19 ms
8,528 KB
testcase_09 AC 19 ms
8,536 KB
testcase_10 AC 60 ms
9,192 KB
testcase_11 AC 19 ms
8,540 KB
testcase_12 AC 19 ms
8,492 KB
testcase_13 AC 18 ms
8,568 KB
testcase_14 AC 18 ms
8,628 KB
testcase_15 AC 18 ms
8,488 KB
testcase_16 AC 19 ms
8,588 KB
testcase_17 AC 18 ms
8,608 KB
testcase_18 AC 37 ms
8,748 KB
testcase_19 AC 52 ms
8,880 KB
testcase_20 AC 52 ms
8,924 KB
testcase_21 AC 50 ms
8,932 KB
testcase_22 AC 52 ms
8,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
Yukicoder No. 004 おもりと天秤

author: yamaton
date: 2015-12-18
"""

import itertools
import collections
import sys

def solve(xs, n):
    total = sum(xs)
    if total % 2 == 1:
        return False
    goal = total // 2

    accum_weights = collections.defaultdict(int)
    for x in xs:
        for w in list(accum_weights):
            accum_weights[x + w] += 1
        accum_weights[x] += 1
    return accum_weights[goal] > 0


def pp(*args, **kwargs):
    return print(*args, file=sys.stderr, **kwargs)


def tf2msg(tf):
    return 'possible' if tf else 'impossible'


def main():
    n = int(input())
    xs = [int(i) for i in input().split()]
    assert len(xs) == n
    result = tf2msg(solve(xs, n))
    print(result)


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