結果

問題 No.4 おもりと天秤
ユーザー cm-araicm-arai
提出日時 2020-12-24 15:03:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 756 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 11,792 KB
実行使用メモリ 10,180 KB
最終ジャッジ日時 2023-10-21 15:41:35
合計ジャッジ時間 7,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,180 KB
testcase_01 AC 29 ms
10,072 KB
testcase_02 AC 35 ms
10,072 KB
testcase_03 AC 30 ms
10,072 KB
testcase_04 AC 29 ms
10,076 KB
testcase_05 AC 29 ms
10,092 KB
testcase_06 AC 29 ms
10,072 KB
testcase_07 AC 29 ms
10,092 KB
testcase_08 AC 30 ms
10,072 KB
testcase_09 AC 29 ms
10,092 KB
testcase_10 AC 29 ms
10,092 KB
testcase_11 AC 30 ms
10,072 KB
testcase_12 AC 28 ms
10,072 KB
testcase_13 AC 30 ms
10,072 KB
testcase_14 AC 30 ms
10,072 KB
testcase_15 AC 29 ms
10,072 KB
testcase_16 AC 29 ms
10,072 KB
testcase_17 AC 29 ms
10,072 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


# 最終的には片方の天秤に全体の半分の重さが乗る
sum_weight = sum(W) / 2
# 割り切れなければ(少数を含む)天秤は釣り合わない
if not sum_weight.is_integer():
    print("impossible")
    exit(0)
else:
    sum_weight = int(sum_weight)


def comb(i, sum):
    """
    可能な組み合わせの合計値にsum_weightが入っていれば即処理終了させる
    """
    global W
    if sum > sum_weight:
        return
    if i == len(W):
        if sum == sum_weight:
            print("possible")
            exit(0)
        return
    # print(f"i={i}")
    comb(i+1, sum + W[i])
    # print(f"i!={i}")
    comb(i+1, sum)


comb(0, 0)
print("impossible")
0