結果

問題 No.4 おもりと天秤
ユーザー Taketo YoshidaTaketo Yoshida
提出日時 2020-03-11 11:33:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,712 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,296 KB
実行使用メモリ 70,016 KB
最終ジャッジ日時 2024-04-27 19:10:39
合計ジャッジ時間 2,173 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
64,940 KB
testcase_01 AC 53 ms
64,512 KB
testcase_02 AC 56 ms
65,792 KB
testcase_03 AC 53 ms
65,920 KB
testcase_04 AC 53 ms
66,304 KB
testcase_05 AC 58 ms
69,376 KB
testcase_06 AC 51 ms
64,640 KB
testcase_07 AC 58 ms
69,504 KB
testcase_08 AC 51 ms
64,512 KB
testcase_09 AC 54 ms
70,016 KB
testcase_10 AC 56 ms
69,248 KB
testcase_11 AC 50 ms
64,768 KB
testcase_12 AC 50 ms
64,512 KB
testcase_13 AC 51 ms
64,640 KB
testcase_14 AC 49 ms
64,256 KB
testcase_15 AC 48 ms
64,640 KB
testcase_16 AC 50 ms
65,408 KB
testcase_17 AC 49 ms
64,640 KB
testcase_18 AC 53 ms
68,480 KB
testcase_19 AC 55 ms
68,864 KB
testcase_20 AC 58 ms
68,864 KB
testcase_21 AC 59 ms
69,248 KB
testcase_22 AC 60 ms
68,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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