結果

問題 No.4 おもりと天秤
ユーザー otsunekootsuneko
提出日時 2021-04-25 02:16:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 549 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 88,948 KB
最終ジャッジ日時 2023-09-17 13:58:51
合計ジャッジ時間 3,193 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,468 KB
testcase_01 AC 72 ms
71,464 KB
testcase_02 AC 81 ms
76,056 KB
testcase_03 AC 75 ms
71,252 KB
testcase_04 AC 75 ms
71,384 KB
testcase_05 AC 74 ms
71,124 KB
testcase_06 AC 72 ms
71,476 KB
testcase_07 AC 72 ms
71,108 KB
testcase_08 AC 71 ms
71,264 KB
testcase_09 AC 73 ms
71,376 KB
testcase_10 AC 73 ms
71,124 KB
testcase_11 AC 73 ms
71,232 KB
testcase_12 AC 72 ms
71,264 KB
testcase_13 AC 73 ms
71,308 KB
testcase_14 AC 74 ms
71,176 KB
testcase_15 AC 74 ms
71,448 KB
testcase_16 AC 73 ms
71,352 KB
testcase_17 AC 73 ms
71,504 KB
testcase_18 AC 153 ms
88,948 KB
testcase_19 AC 73 ms
71,384 KB
testcase_20 AC 74 ms
71,112 KB
testcase_21 AC 74 ms
71,304 KB
testcase_22 AC 75 ms
71,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
def dfs(idx,w):
    if idx == N or (idx,w) in seen:
        return
    if w + W[idx] == total_w/2:
        print("possible")
        exit()
    elif w + W[idx] < total_w/2:
        seen.add((idx,w))
        dfs(idx+1,w+W[idx])
        dfs(idx+1,w)
    else:
        seen.add((idx,w))
        dfs(idx+1,w)

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

if total_w/2 != total_w//2:
    print("impossible")
    exit()

seen = set([])
dfs(0,0)
print("impossible")
0