結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
ckawatak
|
| 提出日時 | 2017-07-13 17:50:01 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 599 bytes |
| コンパイル時間 | 216 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 17,576 KB |
| 最終ジャッジ日時 | 2024-10-07 18:24:03 |
| 合計ジャッジ時間 | 6,877 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 17 |
ソースコード
n = int(input())
values = list(map(int, input().split(' ')))
import functools
from collections import deque
total = functools.reduce(lambda x,y: x+y, values)
def yes(target):
queue = deque()
queue.appendleft((0,0))
while 0 < len(queue):
i, sum = queue.popleft()
if sum == target:
return True
if i == n:
continue
queue.appendleft((i+1,sum))
queue.appendleft((i+1,sum+values[i]))
return False
if total%2 != 0:
print('impossible')
else:
print('possible' if yes(total/2) else 'impossible')
ckawatak