結果
| 問題 |
No.643 Two Operations No.2
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-06-25 01:53:05 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 692 bytes |
| コンパイル時間 | 210 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2024-06-25 01:53:06 |
| 合計ジャッジ時間 | 1,418 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
from collections import deque
X,Y=map(int,input().split())
DP=[[10**6]*600 for i in range(600)]
# DP[0][0] は(-300,-300)
Q=deque()
for i in range(600):
DP[i][i]=0
Q.append((i,i))
while Q:
x,y=Q.popleft()
x1=x-300
y1=y-300
if DP[y][x]>DP[x][y]+1:
DP[y][x]=DP[x][y]+1
Q.append((y,x))
if (x1+y1)%2==0:
x2=(x1+y1)//2
y2=(x1-y1)//2
#print(x1,y1,x2,y2)
if 0<=x2+300<600 and 0<=y2+300<600 and DP[x2+300][y2+300]>DP[x][y]+1:
DP[x2+300][y2+300]=DP[x][y]+1
Q.append((x2+300,y2+300))
if DP[X-300][Y-300]>=10**5:
print(-1)
else:
print(DP[X-300][Y-300])
titia