結果

問題 No.4 おもりと天秤
ユーザー Navier_Boltzmann
提出日時 2022-11-28 07:26:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 581 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,000 KB
実行使用メモリ 62,976 KB
最終ジャッジ日時 2024-10-05 03:05:29
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import *
from functools import *
from itertools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N = int(input())
W = list(map(int,input().split()))
S = sum(W)
if S%2:
    print('impossible')
    exit()
    
T = S//2
M = 10**4+2
dp = [False]*M
dp[0]=True
dp[W[0]]=True
def f(x):
    return min(x,M-1)
for i in range(N-1):
    w = W[i+1]
    for j in range(M-1,-1,-1):
        if dp[j]:
            dp[f(j+w)]=True
if dp[T]:
    print('possible')
else:
    print('impossible')
0