結果

問題 No.4 おもりと天秤
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-02-09 01:32:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 585 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 12,912 KB
最終ジャッジ日時 2023-09-14 04:04:26
合計ジャッジ時間 7,040 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,344 KB
testcase_01 AC 15 ms
8,232 KB
testcase_02 AC 48 ms
8,472 KB
testcase_03 AC 17 ms
8,320 KB
testcase_04 AC 43 ms
8,480 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
W = list(map(int, input().split()))

total_w = sum(W)
if total_w % 2 == 1:
    print("impossible")
    exit(0)


from copy import copy
def dfs(idx, lst):
    if sum(lst) == total_w // 2:
        return lst
    elif idx == N:
        return -1
    
    n_lst = copy(lst)
    res1 = dfs(idx+1, n_lst+[W[idx]])
    res2 = dfs(idx+1, n_lst)
    if res1 != -1 or res2 != -1:
        return 1
    else:
        return -1

if dfs(0, [])==1:
    print("possible")
else:
    print("impossible")

    

0