結果
| 問題 |
No.1538 引きこもりさんは引き算が得意。
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:51:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,355 bytes |
| コンパイル時間 | 517 ms |
| コンパイル使用メモリ | 81,396 KB |
| 実行使用メモリ | 471,220 KB |
| 最終ジャッジ日時 | 2025-04-16 00:52:55 |
| 合計ジャッジ時間 | 6,394 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 TLE * 1 -- * 19 |
ソースコード
from itertools import combinations
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
visited = set()
q = deque()
initial = tuple(sorted(a))
q.append(initial)
visited.add(initial)
found = False
while q:
current = q.popleft()
if k in current:
found = True
break
m = len(current)
if m < 2:
continue
# Generate all possible pairs
for i in range(m):
for j in range(i+1, m):
x = current[i]
y = current[j]
# Generate new numbers
new_num1 = x - y
new_num2 = y - x
# Create new lists
new_list1 = list(current)
del new_list1[j], new_list1[i]
new_list1.append(new_num1)
new_list1_sorted = tuple(sorted(new_list1))
if new_list1_sorted not in visited:
visited.add(new_list1_sorted)
q.append(new_list1_sorted)
# For the second possibility
new_list2 = list(current)
del new_list2[j], new_list2[i]
new_list2.append(new_num2)
new_list2_sorted = tuple(sorted(new_list2))
if new_list2_sorted not in visited:
visited.add(new_list2_sorted)
q.append(new_list2_sorted)
print("Yes" if found else "No")
lam6er