結果

問題 No.4 おもりと天秤
コンテスト
ユーザー phantomile
提出日時 2015-12-19 08:40:58
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 776 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 440 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-13 01:51:18
合計ジャッジ時間 3,949 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""
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