結果

問題 No.4 おもりと天秤
ユーザー こるこる
提出日時 2017-01-04 13:23:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 597 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 12,436 KB
最終ジャッジ日時 2023-09-08 17:16:35
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,208 KB
testcase_01 AC 15 ms
8,116 KB
testcase_02 AC 15 ms
8,300 KB
testcase_03 AC 15 ms
8,276 KB
testcase_04 AC 15 ms
8,200 KB
testcase_05 AC 28 ms
10,544 KB
testcase_06 AC 15 ms
7,792 KB
testcase_07 AC 29 ms
10,596 KB
testcase_08 AC 15 ms
8,112 KB
testcase_09 AC 37 ms
12,436 KB
testcase_10 AC 29 ms
10,708 KB
testcase_11 AC 16 ms
7,816 KB
testcase_12 AC 16 ms
7,768 KB
testcase_13 AC 15 ms
7,804 KB
testcase_14 AC 15 ms
7,812 KB
testcase_15 AC 15 ms
7,772 KB
testcase_16 AC 15 ms
8,224 KB
testcase_17 AC 14 ms
8,252 KB
testcase_18 AC 49 ms
10,360 KB
testcase_19 AC 25 ms
10,212 KB
testcase_20 AC 26 ms
10,320 KB
testcase_21 AC 25 ms
9,952 KB
testcase_22 AC 27 ms
10,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

n=int(input())
w=[int(i) for i in input().split()]

weight=sum(w)
if weight%2!=0:
    print("impossible")
    sys.exit()
weight=int(weight/2)

dp=[[False for i in range(weight+1)] for j in range(n+1)]

def dfs(index,weight):

    if weight<0:
        return False

    if dp[index][weight]:
        return False

    if index==n:
        if weight==0:
            print("possible")
            sys.exit()
        return False

    dfs(index+1,weight-w[index])
    dfs(index+1,weight)

    dp[index][weight]=True

    return False


dfs(1,weight-w[0])
dfs(1,weight)

print("impossible")
0