結果

問題 No.4 おもりと天秤
コンテスト
ユーザー Taketo Yoshida
提出日時 2020-03-11 11:33:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 1,712 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 224 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 70,144 KB
最終ジャッジ日時 2026-05-11 03:07:04
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N = I()
    W = LI()
    total = sum(W)

    if total % 2 == 1:
        print('impossible')
        return

    half = total // 2
    dp = [0] * (half+1)
    dp[0] = 1

    for i in range(N):
        dp_next = [0] * (half+1)
        dp_next[0] = 1
        for j in range(half+1):
            if dp[j] == 1:
                dp_next[j] = 1
                if j + W[i] <= half:
                    dp_next[j+W[i]] = 1
        # print(i, dp_next)
        dp = dp_next

    if dp[half] == 0:
        print('impossible')
    else:
        print('possible')


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