結果

問題 No.4 おもりと天秤
ユーザー dn6049949
提出日時 2022-04-15 22:28:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 920 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 66,816 KB
最終ジャッジ日時 2024-12-25 01:23:55
合計ジャッジ時間 2,512 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def main():
    n = I()
    w = LI()
    s = sum(w)
    if s&1:
        print("impossible")
        return
    s >>= 1
    dp = [0]*(s+1)
    dp[0] = 1
    for wi in w:
        for j in reversed(range(s)):
            if not dp[j]:
                continue
            nj = j+wi
            if nj == s:
                print("possible")
                return
            if nj < s:
                dp[nj] = 1
    print("impossible")
    return


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