結果

問題 No.4 おもりと天秤
ユーザー tcltktcltk
提出日時 2021-01-19 07:57:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 250 ms / 5,000 ms
コード長 955 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 91,692 KB
最終ジャッジ日時 2023-08-22 04:13:07
合計ジャッジ時間 7,153 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
83,420 KB
testcase_01 AC 226 ms
83,036 KB
testcase_02 AC 232 ms
83,256 KB
testcase_03 AC 230 ms
83,628 KB
testcase_04 AC 226 ms
83,592 KB
testcase_05 AC 238 ms
83,648 KB
testcase_06 AC 227 ms
83,268 KB
testcase_07 AC 237 ms
83,568 KB
testcase_08 AC 226 ms
83,288 KB
testcase_09 AC 250 ms
91,692 KB
testcase_10 AC 242 ms
83,508 KB
testcase_11 AC 230 ms
83,448 KB
testcase_12 AC 231 ms
83,308 KB
testcase_13 AC 231 ms
82,948 KB
testcase_14 AC 237 ms
83,540 KB
testcase_15 AC 233 ms
83,300 KB
testcase_16 AC 232 ms
83,516 KB
testcase_17 AC 232 ms
83,220 KB
testcase_18 AC 244 ms
83,800 KB
testcase_19 AC 250 ms
83,348 KB
testcase_20 AC 241 ms
83,544 KB
testcase_21 AC 247 ms
83,548 KB
testcase_22 AC 240 ms
83,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)

YES = 'possible'
NO = 'impossible'


def main():
    N = int(input())
    W = list(map(int, input().split()))

    SumW = sum(W)
    if SumW % 2 == 1:
        print(NO)
        return

    dp = [[False for _ in range(SumW+1)] for _ in range(N+1)]
    dp[0][0] = True
    for i in range(N):
        for w in range(SumW+1):
            if dp[i][w]:
                dp[i+1][w] = True
                dp[i+1][w+W[i]] = True

    if dp[N][SumW//2]:
        print(YES)
    else:
        print(NO)


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