結果

問題 No.4 おもりと天秤
ユーザー nidosinonidosino
提出日時 2017-06-03 03:44:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,560 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 11,848 KB
実行使用メモリ 14,444 KB
最終ジャッジ日時 2023-10-22 02:20:49
合計ジャッジ時間 7,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

'''
授業中にもかかわらず遊んでしまうdaveは、
理科の実験中に、色んな重さの種類があるおもりをすべて使って、
ちょうど天秤が水平になるおもりの組み合わせがあるかを知りたくなったようで、それに遊び呆けてる。
(すべてのおもりを使うため、使わなかったおもりはない。)

あなたは、daveにその組み合わせがあるかどうか教えて、授業に集中させるようにしてください。

もしそのような組み合わせがあれば possiblepossible 、なければ impossibleimpossible を出力してください。
'''


def last_one(l):
    last_index = 0
    for num_i, i in enumerate(l):
        if i == 1:
            last_index = num_i
    return last_index


def match_sum(l, a, where_sum=0):

    for num_i, i in enumerate(l):
        #print(i, a)
        if i < a:
            r_list = match_sum(l[num_i + 1:], a - i, where_sum + num_i + 1)
            if -1 not in r_list:
                return [num_i + where_sum] + r_list
            else:
                continue
        elif i == a:
            return [num_i + where_sum]
    return [-1]

if __name__ == '__main__':

    A = int(input())
    S = list(map(int, input().split()))
    S.sort()
    S.reverse()
    half_sum = sum(S) / 2

    if sum(S) % 2 == 1:
        print("impossible")
    else:
        if -1 in match_sum(S, half_sum):
            print("impossible")
        else:
            print("possible")
0