結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2021-04-25 02:16:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 117 ms / 5,000 ms |
コード長 | 549 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 85,120 KB |
最終ジャッジ日時 | 2024-07-04 09:22:39 |
合計ジャッジ時間 | 2,032 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
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")