結果

問題 No.4 おもりと天秤
ユーザー ronpooronpoo
提出日時 2023-08-22 10:51:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2023-08-22 10:51:14
合計ジャッジ時間 3,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,548 KB
testcase_01 AC 73 ms
71,276 KB
testcase_02 AC 76 ms
75,704 KB
testcase_03 AC 75 ms
75,844 KB
testcase_04 AC 76 ms
76,108 KB
testcase_05 AC 84 ms
76,156 KB
testcase_06 AC 72 ms
71,248 KB
testcase_07 AC 85 ms
76,160 KB
testcase_08 AC 71 ms
71,188 KB
testcase_09 AC 80 ms
75,972 KB
testcase_10 AC 83 ms
76,056 KB
testcase_11 AC 74 ms
75,724 KB
testcase_12 AC 71 ms
71,324 KB
testcase_13 AC 73 ms
71,448 KB
testcase_14 AC 71 ms
71,368 KB
testcase_15 AC 72 ms
71,064 KB
testcase_16 AC 73 ms
75,704 KB
testcase_17 AC 71 ms
71,316 KB
testcase_18 AC 83 ms
76,124 KB
testcase_19 AC 84 ms
76,004 KB
testcase_20 AC 86 ms
76,000 KB
testcase_21 AC 83 ms
76,088 KB
testcase_22 AC 83 ms
75,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

total = sum(W)
if total % 2 == 1:
    print('impossible')
    exit()
    
half = total // 2
dp = [[False]*(half+1) for _ in range(N+1)]
dp[0][0] = True
for i in range(N):
    for j in range(half+1):
        if not dp[i][j]:
            continue
        dp[i+1][j] = True
        if j + W[i] <= half:
            dp[i+1][j+W[i]] = True

if dp[N][half]:
    print('possible')
else:
    print('impossible')
0