結果

問題 No.4 おもりと天秤
ユーザー otsunekootsuneko
提出日時 2021-04-25 01:44:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 574 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 100,488 KB
最終ジャッジ日時 2023-09-17 13:58:23
合計ジャッジ時間 4,671 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,264 KB
testcase_01 AC 75 ms
71,424 KB
testcase_02 AC 96 ms
76,704 KB
testcase_03 AC 77 ms
71,100 KB
testcase_04 AC 83 ms
76,016 KB
testcase_05 AC 76 ms
71,516 KB
testcase_06 AC 74 ms
71,304 KB
testcase_07 AC 73 ms
71,436 KB
testcase_08 AC 74 ms
71,204 KB
testcase_09 AC 76 ms
71,508 KB
testcase_10 AC 74 ms
71,256 KB
testcase_11 AC 74 ms
71,232 KB
testcase_12 AC 75 ms
71,268 KB
testcase_13 AC 76 ms
71,092 KB
testcase_14 AC 75 ms
71,232 KB
testcase_15 AC 75 ms
71,044 KB
testcase_16 WA -
testcase_17 AC 78 ms
71,104 KB
testcase_18 AC 1,229 ms
100,488 KB
testcase_19 AC 74 ms
71,504 KB
testcase_20 AC 75 ms
70,988 KB
testcase_21 AC 73 ms
70,972 KB
testcase_22 AC 73 ms
71,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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