結果

問題 No.4 おもりと天秤
ユーザー Woo-Cie
提出日時 2019-03-23 10:00:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 934 ms / 5,000 ms
コード長 567 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 46,744 KB
最終ジャッジ日時 2024-09-22 00:25:23
合計ジャッジ時間 18,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8-*-
import numpy as np
if __name__ == '__main__':
    n = int(input())
    w = np.array(list(map(int, input().split(" "))))
    s = sum(w)
    if s % 2 == 1:
        print("impossible")
        exit()
    s //= 2
    t = np.zeros((n+1, s+1))
    t[0,0] = 1
    for i in range(n):
        for j in range(s+1):
            if t[i, j] == 1:
                t[i+1, j] = 1
                if j + w[i] <= s:
                    t[i+1, j+w[i]] = 1
    if t[n,s] == 1:
        print("possible")
    else:
        print("impossible")
0