結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-08-20 23:37:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 941 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 48,384 KB |
最終ジャッジ日時 | 2024-11-07 21:40:21 |
合計ジャッジ時間 | 7,116 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 5 TLE * 1 -- * 17 |
ソースコード
def search(N, ws, Sum): q = [Sum] s = [0] res = False while q: target = q.pop(0) start = s.pop(0) for i in range(start, N): d = target - ws[i] if d == 0: res = True q.clear() break elif d < 0: continue elif d > 0: q_ = [target - ws[j] for j in range(i, N)] q.extend(q_) s_ = [j for j in range(i+1, N+1)] s.extend(s_) # print(q) break return res def main(): N = int(input()) ws = list(map(int, input().split())) ws.sort() ws.reverse() ws_sum = sum(ws) if ws_sum % 2 == 0: Sum = ws_sum // 2 res = search(N, ws, Sum) else: res = False print(ws_sum / 2) if res: print('possible') else: print('impossible') main()