Contest Duration: ~ (local time) (100 minutes) Back to Home

Submission #10881245

Source Code Expand

Copy
```import sys

def solve(A,B,C,D,E=3**30):
# 大きさEの穴まで考慮
if not E:
return abs(A-C) + abs(B-D)
a = A//E
b = B//E
c = C//E
d = D//E
if a != c and b != d:
return abs(A-C) + abs(B-D)
if a == c and b == d:
return solve(A,B,C,D,E//3)
if b == d and a != c:
A,B = B,A
a,b = b,a
C,D = D,C
c,d = d,c
if a == c and b != d:
if a % 3 != 1:
return solve(A,B,C,D,E//3)
if abs(b-d) == 1:
return solve(A,B,C,D,E//3)
if B > D:
A,B,C,D = C,D,A,B
a,b,c,d = c,d,a,b
x1 = E * a - 1
y1 = E * (b+1) - 1
y2 = E * d
dist1 = abs(x1-A) + abs(y1-B) + abs(y1-y2) + abs(x1-C) + abs(y2-D)
x1 = E * (a+1)
y1 = E * (b+1) - 1
y2 = E * d
dist2 = abs(x1-A) + abs(y1-B) + abs(y1-y2) + abs(x1-C) + abs(y2-D)
return min(dist1, dist2)

solve(2,1,3,1)

for A,B,C,D in zip(m,m,m,m):
print(solve(A-1,B-1,C-1,D-1,3**30))

```

Submission Info

Submission Time 2020-03-14 22:22:36+0900 F - Fractal Shortest Path maspy Python3 (3.4.3) 600 1235 Byte AC 150 ms 5788 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0.txt
All 600 / 600 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, example0.txt
Case Name Status Exec Time Memory
000.txt 150 ms 4952 KB
001.txt 133 ms 5788 KB
002.txt 134 ms 5788 KB
003.txt 134 ms 5788 KB
004.txt 134 ms 5788 KB
005.txt 132 ms 5788 KB
006.txt 134 ms 5788 KB
007.txt 132 ms 5788 KB
008.txt 134 ms 5788 KB
009.txt 133 ms 5788 KB
010.txt 133 ms 5788 KB
011.txt 135 ms 5788 KB
012.txt 134 ms 5788 KB
013.txt 132 ms 5788 KB
014.txt 132 ms 5788 KB
015.txt 134 ms 5788 KB
016.txt 134 ms 5788 KB
017.txt 132 ms 5788 KB
018.txt 136 ms 5788 KB
019.txt 135 ms 5788 KB
020.txt 133 ms 5788 KB
example0.txt 18 ms 3064 KB