結果

問題 No.4 おもりと天秤
ユーザー CsTarepandaCsTarepanda
提出日時 2017-05-04 00:22:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 452 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 11,324 KB
最終ジャッジ日時 2023-09-08 17:25:31
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,104 KB
testcase_01 AC 16 ms
8,108 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 16 ms
8,132 KB
testcase_04 AC 16 ms
8,184 KB
testcase_05 AC 16 ms
8,260 KB
testcase_06 AC 15 ms
7,992 KB
testcase_07 AC 16 ms
8,240 KB
testcase_08 AC 16 ms
8,104 KB
testcase_09 AC 16 ms
8,284 KB
testcase_10 AC 16 ms
8,172 KB
testcase_11 AC 16 ms
7,904 KB
testcase_12 AC 15 ms
7,820 KB
testcase_13 AC 16 ms
7,872 KB
testcase_14 AC 15 ms
7,824 KB
testcase_15 AC 15 ms
7,836 KB
testcase_16 AC 16 ms
8,108 KB
testcase_17 AC 16 ms
8,120 KB
testcase_18 AC 59 ms
11,324 KB
testcase_19 AC 16 ms
8,152 KB
testcase_20 AC 16 ms
8,176 KB
testcase_21 AC 16 ms
8,160 KB
testcase_22 AC 16 ms
8,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
if ans & 1:
    print("impossible")
    sys.exit()
ans >>= 1

dp = [{} for x in range(n)]

def solve(i, w):
    if w < 0 or i >= n:
        return None
    if w == 0:
        print("possible")
        sys.exit()
        return None
    if dp[i].get(w):
        return None
    dp[i][w] = True
    solve(i + 1, w - a[i])
    solve(i + 1, w)

solve(0, ans)
print("impossible")
0