結果

問題 No.4 おもりと天秤
ユーザー dn6049949dn6049949
提出日時 2022-04-15 22:28:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 920 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 76,512 KB
最終ジャッジ日時 2023-08-26 08:15:31
合計ジャッジ時間 4,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,260 KB
testcase_01 AC 94 ms
71,668 KB
testcase_02 AC 97 ms
76,468 KB
testcase_03 AC 97 ms
76,216 KB
testcase_04 AC 97 ms
76,404 KB
testcase_05 AC 98 ms
76,432 KB
testcase_06 AC 89 ms
71,472 KB
testcase_07 AC 99 ms
76,424 KB
testcase_08 AC 92 ms
71,328 KB
testcase_09 AC 98 ms
76,368 KB
testcase_10 AC 100 ms
76,488 KB
testcase_11 AC 96 ms
76,408 KB
testcase_12 AC 94 ms
71,684 KB
testcase_13 AC 93 ms
71,296 KB
testcase_14 AC 93 ms
71,204 KB
testcase_15 AC 93 ms
71,500 KB
testcase_16 AC 100 ms
76,364 KB
testcase_17 AC 93 ms
71,100 KB
testcase_18 AC 102 ms
76,452 KB
testcase_19 AC 101 ms
76,436 KB
testcase_20 AC 101 ms
76,512 KB
testcase_21 AC 98 ms
76,224 KB
testcase_22 AC 99 ms
76,228 KB
権限があれば一括ダウンロードができます

ソースコード

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