Problem:


Score : 900 points

Problem Statement

In the city of Nevermore, there are 10^8 streets and 10^8 avenues, both numbered from 0 to 10^8-1.
All streets run straight from west to east, and all avenues run straight from south to north.
The distance between neighboring streets and between neighboring avenues is exactly 100 meters.

Every street intersects every avenue. Every intersection can be described by pair (x, y), where x is avenue ID and y is street ID.

There are N fountains in the city, situated at intersections (X_i, Y_i).
Unlike normal intersections, there's a circle with radius 10 meters centered at the intersection, and there are no road parts inside this circle.

The picture below shows an example of how a part of the city with roads and fountains may look like.

City governors don't like encountering more than one fountain while moving along the same road.
Therefore, every street contains at most one fountain on it, as well as every avenue.

Citizens can move along streets, avenues and fountain perimeters.
What is the shortest distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2)?

Constraints

0 \leq x_1, y_1, x_2, y_2 < 10^8

1 \leq N \leq 200,000

0 \leq X_i, Y_i < 10^8

X_i \neq X_j for i \neq j

Y_i \neq Y_j for i \neq j

Intersections (x_1, y_1) and (x_2, y_2) are different and don't contain fountains.

All input values are integers.

Input

Input is given from Standard Input in the following format:

x_1 y_1 x_2 y_2
N
X_1 Y_1
X_2 Y_2
:
X_N Y_N

Output

Print the shortest possible distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2), in meters.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-11}.

Sample Input 1

1 1 6 5
3
3 2
5 3
2 4

Sample Output 1

891.415926535897938

One possible shortest path is shown on the picture below. The path starts at the blue point, finishes at the purple point and follows along the red line.

Sample Input 2

3 5 6 4
3
3 2
5 3
2 4

Sample Output 2

400.000000000000000

Sample Input 3

4 2 2 2
3
3 2
5 3
2 4

Sample Output 3

211.415926535897938



Sample input:
1 1 6 5
3
3 2
5 3
2 4


Sample output:
891.415926535897938

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from math import atan
def lis(L):
    if not L:
        return 0
    seq = [L[0]]
    for i in L[1:]:
        if seq[-1] < i:
            seq.append(i)
        else:
            seq[bisect.bisect_left(seq, i)] = i
    return len(seq)

def mhd(x, y):
    return abs(x) + abs(y)

x1, y1, x2, y2 = map(int, sys.stdin.readline().split())
        
N = int(sys.stdin.readline())

if x1 == x2 or y1 == y2:
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if X != x1:
                continue
            else:
                if y1 <= Y <= y2:
                    print(100*mhd(0, y1-y2) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(0, y1-y2))
                    sys.exit()
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if Y != y1:
                continue
            else:
                if x1 <= X <= x2:
                    print(100*mhd(x1-x2, 0) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(x1-x2, 0))
                    sys.exit()
if x1 > x2:
    y1, y2 = y2, y1

geta = 10**9+7
B = []
if y1 < y2:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y1 <= Y <= y2:
            B.append(X*geta + Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))
    
else:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y2 <= Y <= y1:
            B.append(X*geta - Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from math import atan
def lis(L):
    if not L:
        return 0
    seq = [L[0]]
    for i in L[1:]:
        if seq[-1] < i:
            seq.append(i)
        else:
            seq[bisect.bisect_left(seq, i)] = i
    return len(seq)

def mhd(x, y):
    return abs(x) + abs(y)

x1, y1, x2, y2 = map(int, sys.stdin.readline().split())
        
N = int(sys.stdin.readline())

if x1 == x2 or y1 == y2:
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if X != x1:
                continue
            else:
                if y1 <= Y <= y2:
                    print(100*mhd(0, y1-y2) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(0, y1-y2))
                    sys.exit()
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if Y != y1:
                continue
            else:
                if x1 <= X <= x2:
                    print(100*mhd(x1-x2, 0) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(x1-x2, 0))
                    sys.exit()
if x1 > x2:
    y1, y2 = y2, y1

geta = 19**9+7
B = []
if y1 < y2:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y1 <= Y <= y2:
            B.append(X*geta + Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))
    
else:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y2 <= Y <= y1:
            B.append(X*geta - Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from math import atan
def lis(L):
    if not L:
        return 0
    seq = [L[0]]
    for i in L[1:]:
        if seq[-1] < i:
            seq.append(i)
        else:
            seq[bisect.bisect_left(seq, i)] = i
    return len(seq)

def mhd(x, y):
    return abs(x) + abs(y)

x1, y1, x2, y2 = map(int, sys.stdin.readline().split())
        
N = int(sys.stdin.readline())

if x1 == x2 or y1 == y2:
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if X != x1:
                continue
            else:
                if y1 <= Y <= y2:
                    print(100*mhd(0, y1-y2) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(0, y1-y2))
                    sys.exit()
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if Y != y1:
                continue
            else:
                if x1 <= X <= x2:
                    print(100*mhd(x1-x2, 0) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(x1-x2, 0))
                    sys.exit()
if x1 > x2:
    y1, y2 = y2, y1

geta = 19**9+7
B = []
if y1 < y2:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y1 <= Y <= y2:
            B.append(X*geta + Y)
    B.sort()
    B = [b%geta for b in B]
    print(100*mhd(x1-x2, y1-y2) + lis(B)*(20*atan(1)-20))
    
else:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y2 <= Y <= y1:
            B.append(X*geta - Y)
    B.sort()
    B = [b%geta for b in B]
    print(100*mhd(x1-x2, y1-y2) + lis(B)*(20*atan(1)-20))

Submission status: Wrong Answer

Solution code:
import math
from bisect import bisect
x1,y1,x2,y2 = map(int,input().split())
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
src.sort()
if x1 > x2:
    x1,x2 = x2,x1
    y1,y2 = y2,y1

arc = 5 * math.pi

if x1 == x2:
    if y1 > y2:
        y1,y2 = y2,y1
    ans = 100 * (y2-y1)
    for x,y in src:
        if x == x1 and y1 < y < y2:
            ans += arc*2 - 20
            break
    print(ans)
    exit()

if y1 == y2:
    if x1 > x2:
        x1,x2 = x2,x1
    ans = 100 * (x2-x1)
    for x,y in src:
        if y == y1 and x1 < x < x2:
            ans += arc*2 - 20
            break
    print(ans)
    exit()

if y1 < y2:
    lis = []
    for x,y in src:
        if x < x1: continue
        if x > x2: break
        if not y1 <= y <= y2: continue
        i = bisect(lis, y)
        if i == len(lis):
            lis.append(y)
        else:
            lis[i] = y
    ans = 100 * (x2-x1 + y2-y1)
    if len(lis) in (x2-x1, y2-y1):
        ans += (len(lis)-1) * (arc - 20)
        ans += arc*2 - 20
    else:
        ans += len(lis) * (arc - 20)
    print(ans)
else:
    lds = []
    for x,y in src:
        if x < x1: continue
        if x > x2: break
        if not y2 <= y <= y1: continue
        i = bisect(lds, -y)
        if i == len(lds):
            lds.append(-y)
        else:
            lds[i] = -y
    ans = 100 * (x2-x1 + y1-y2)
    if len(lds) in (x2-x1, y1-y2):
        ans += (len(lds)-1) * (arc - 20)
        ans += arc*2 - 20
    else:
        ans += len(lds) * (arc - 20)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
from bisect import bisect
x1,y1,x2,y2 = map(int,input().split())
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
src.sort()
if x1 > x2:
    x1,x2 = x2,x1
    y1,y2 = y2,y1

arc = 5 * math.pi

if x1 == x2:
    if y1 > y2:
        y1,y2 = y2,y1
    ans = 100 * (y2-y1)
    for x,y in src:
        if x == x1 and y1 < y < y2:
            ans += arc*2 - 20
            break
    print(ans)
    exit()

if y1 == y2:
    if x1 > x2:
        x1,x2 = x2,x1
    ans = 100 * (x2-x1)
    for x,y in src:
        if y == y1 and x1 < x < x2:
            ans += arc*2 - 20
            break
    print(ans)
    exit()

if y1 < y2:
    lis = []
    for x,y in src:
        if x < x1: continue
        if x > x2: break
        if not y1 <= y <= y2: continue
        i = bisect(lis, y)
        if i == len(lis):
            lis.append(y)
        else:
            lis[i] = y
    ans = 100 * (x2-x1 + y2-y1)
    ans += len(lis) * (arc - 20)
    print(ans)
else:
    lds = []
    for x,y in src:
        if x < x1: continue
        if x > x2: break
        if not y2 <= y <= y1: continue
        i = bisect(lds, -y)
        if i == len(lds):
            lds.append(-y)
        else:
            lds[i] = -y
    ans = 100 * (x2-x1 + y1-y2)
    ans += len(lds) * (arc - 20)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res

def main():
    txy = LI()
    x1,y1,x2,y2 = txy
    n = I()
    a = [LI() for _ in range(n)]
    im = 10**8
    xs = set([x1,x2])
    ys = set([y1,y2])
    for x,y in a:
        xs.add(x)
        ys.add(y)
    xd = {}
    yd = {}
    i = 0
    for x in sorted(list(xs)):
        xd[x] = i
        i += 1
    i = 0
    for y in sorted(list(ys)):
        yd[y] = i
        i += 1
    x1 = xd[x1]
    x2 = xd[x2]
    y1 = yd[y1]
    y2 = yd[y2]
    a = [[xd[x],yd[y]] for x,y in a]

    if x1 > x2:
        x2,y2,x1,y1 = x1,y1,x2,y2
    if y1 > y2:
        y1 = im - y1
        y2 = im - y2 - y1
        for i in range(n):
            a[i][1] = im - a[i][1] - y1
    else:
        y2 -= y1
        for i in range(n):
            a[i][1] -= y1
    y1 = 0

    x2 -= x1
    for i in range(n):
        a[i][0] -= x1
    x1 = 0

    def f(a,b):
        if a > b:
            return a
        return b

    seg = Seg(y2,0,f)

    for x,y in sorted(a):
        if x < 0 or y < 0 or y > y2:
            continue
        t = seg.query(0,y+1)
        if seg.find(y) > t:
            continue
        seg.update(y, t+1)

    t = seg.total()
    kx = abs(txy[0]-txy[2])
    ky = abs(txy[1]-txy[3])
    r = (kx+ky) * 100
    if t == min(kx, ky) + 1:
        return r - t * 20 + math.pi * 5 * (t-1)  + math.pi * 10

    return r - t * 20 + math.pi * 5 * t


print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res

def main():
    txy = LI()
    x1,y1,x2,y2 = txy
    n = I()
    a = [LI() for _ in range(n)]
    im = 10**8
    xs = set([x1,x2])
    ys = set([y1,y2])
    for x,y in a:
        xs.add(x)
        ys.add(y)
    xd = {}
    yd = {}
    i = 0
    for x in sorted(list(xs)):
        xd[x] = i
        i += 1
    i = 0
    for y in sorted(list(ys)):
        yd[y] = i
        i += 1
    x1 = xd[x1]
    x2 = xd[x2]
    y1 = yd[y1]
    y2 = yd[y2]
    a = [[xd[x],yd[y]] for x,y in a]

    if x1 > x2:
        x2,y2,x1,y1 = x1,y1,x2,y2
    if y1 > y2:
        y1 = im - y1
        y2 = im - y2 - y1
        for i in range(n):
            a[i][1] = im - a[i][1] - y1
    else:
        y2 -= y1
        for i in range(n):
            a[i][1] -= y1
    y1 = 0

    x2 -= x1
    for i in range(n):
        a[i][0] -= x1
    x1 = 0

    def f(a,b):
        if a > b:
            return a
        return b

    seg = Seg(y2,0,f)

    for x,y in sorted(a):
        if x < 0 or y < 0 or y > y2:
            continue
        t = seg.query(0,y)
        if seg.find(y) > t:
            continue
        seg.update(y, t+1)

    t = seg.total()
    kx = abs(txy[0]-txy[2])
    ky = abs(txy[1]-txy[3])
    r = (kx+ky) * 100
    if t == min(kx, ky) + 1:
        return r - t * 20 + math.pi * 5 * (t-1)  + math.pi * 10

    return r - t * 20 + math.pi * 5 * t


print(main())

Submission status: Wrong Answer

Solution code:
import math

M=[int(x) for x in input().split()]
N=int(input())
xd=abs(M[0]-M[2])
yd=abs(M[1]-M[3])
F=[]
for i in range(N):
  a,b=map(int,input().split())
  if min(M[0],M[2])<= a <= max(M[0],M[2]) and min(M[1],M[3])<= b <= max(M[1],M[3]):
    F.append([a,b])
F.sort(key=lambda x:x[0])
dp=[0 for x in range(len(F))]
res=0
for i in range(len(F)):
  dp[i]=1
  for j in range(i):
    if F[j][0]<F[i][0] and F[j][1]<F[i][1]:
      dp[i]=max(dp[i],dp[j]+1)
  res=max(res,dp[i])

if res==min(xd,yd)+1:
  ans=(xd)*100+(yd)*100+(math.pi*10-20)-(20-math.pi*5)*(res-1)  
else:
  ans=(xd)*100+(yd)*100-(20-math.pi*5)*res

print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
ar = [-1] * int(abs(sx-gx)+1)
for i in range(n):
    x,y = list(map(int,input().split()))
    if min(sx,gx) <= x <= max(sx,gx):
        if min(sy,gy) <= y <= max(sy,gy):

            ar[abs(sx - x)] = (abs(sy - y))
ans =[]
# print(ar)
if px == 0:
    ar.reverse()

for i in range(len(ar)):
    f = 0
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if  my < ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if ar[i] < ans[j]:
                    ans[j] = ar[i]
                    f = 1
                    break
            if f == 0 :
                ans.append(ar[i])
# print(ans)
a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
ar = [-1] * int(abs(sx-gx)+1)
for i in range(n):
    x,y = list(map(int,input().split()))
    if min(sx,gx) <= x <= max(sx,gx):
        if min(sy,gy) <= y <= max(sy,gy):
            ar[x-min(sx,gx)] = (abs(sy - y))
ans =[]
# print(ar)
if px == 0:
    ar.reverse()

for i in range(len(ar)):
    f = 0
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if  my < ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if ar[i] < ans[j]:
                    ans[j] = ar[i]
                    f = 1
                    break
            if f == 0 :
                ans.append(ar[i])
# print(ans)
a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]

if px == 0:
    ar.reverse()

for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = max(ar[i],my) if py else min(ar[i],my)
                    break

a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]

if px == 0:
    ar.reverse()

for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = max(ar[i],my)
                    break

a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]

if px == 0:
    ar.reverse()

for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = ar[i]
                    break

a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]

if py == 0:
    ar.reverse()

for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = ar[i]
                    break

a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]
for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = ar[i]
                    break
a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if (sx == gx or sy == gy ) and a else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]
for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = ar[i]
                    break

a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if sx == gx or sy == gy else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
x = [0]*n
y = [0]*n
px = 1 if sx < gx else 0
py = 1 if sy < gy else 0
si = sx if px else gx
ar = [-1] * int(abs(gx-sx)+1)
for i in range(n):
    print(ar)
    x[i],y[i] = list(map(int,input().split()))
    if px and sx <= x[i] <= gx  or px==0 and sx >= x[i] >= gx:
        if py and sy <= y[i] <= gy or py == 0 and sy >= y[i] >= gy:
            ar[abs(x[i]-si)] = y[i]
ans =[]
for i in range(len(ar)):
    if ar[i] == -1:
        continue
    if len(ans) == 0:
        ans.append(ar[i])
        my = ar[i]
    else:
        if py and my < ar[i] or py == 0 and my > ar[i]:
            ans.append(ar[i])
            my = ar[i]
        else:
            for j in range(len(ans)):
                if py and ar[i] < ans[j] or py == 0 and ar[i] > ans[j]:
                    ans[j] = ar[i]
                    my = ar[i]
                    break

a = len(ans)
x = 5*math.pi
ans = (abs(sx-gx) + abs(sy-gy) )*100 - a*20 + a*x 
ans += x if sx == gx or sy == gy else 0
print(ans)

Submission status: Wrong Answer

Solution code:
from math import pi

input1 = list(map(int,input("").split(" ")))
N = int(input(""))
src = {"x":input1[0],"y":input1[1]}
dist = {"x":input1[2],"y":input1[3]}

spring = []
for i in range(N):
	temp = list(map(int,input("").split(" ")))
	if temp[0] in range(min(src['x'],dist['x']),max(src['x'],dist['x'])+1):
		if temp[1] in range(min(src['y'],dist['y']),max(src['y'],dist['y'])+1):
			spring.append({'x':temp[0], 'y':temp[1]})

# print(spring)
path = (abs(src['x']-dist['x']) + abs(src['y']-dist['y'])) * 100
if len(spring) > 0:
	r = 10
	if src['x'] == dist['x'] or src['y'] == dist['y'] :
		#半円
		path += r*pi - 2*r 
	else:
		#1/4円
		if (src['x']-dist['x'])*(src['y']-dist['y']) > 0:
			spring.sort(key=lambda k: k['x'])
		else:
			spring.sort(key=lambda k: k['x'], reverse=True)
		L = [spring[0]['y']]
		length = 1
		for i in range(1,len(spring)):
			if L[length-1] < spring[i]['y']:
				L.append(spring[i]['y'])
				length += 1
			else:
				for j in range(length):
					if spring[i]['y'] <= L[j]:
						L[j] = spring[i]['y']
						break
		path += (r*pi/2 - 2*r) * length

print(path)

Submission status: Wrong Answer

Solution code:
from math import pi

input1 = list(map(int,input("").split(" ")))
N = int(input(""))
src = {"x":input1[0],"y":input1[1]}
dist = {"x":input1[2],"y":input1[3]}

spring = []
for i in range(N):
	temp = list(map(int,input("").split(" ")))
	if temp[0] in range(min(src['x'],dist['x']),max(src['x'],dist['x'])+1):
		if temp[1] in range(min(src['y'],dist['y']),max(src['y'],dist['y'])+1):
			spring.append({'x':temp[0], 'y':temp[1], 'distance':(abs(temp[0]-src['x']) + abs(temp[1]-src['y']))})

# print(spring)
path = (abs(src['x']-dist['x']) + abs(src['y']-dist['y'])) * 100
if len(spring) > 0:
	r = 10
	if src['x'] == dist['x'] or src['y'] == dist['y'] :
		#半円
		path += r*pi - 2*r 
	else:
		#1/4円
		spring.sort(key=lambda k: k['distance'])
		via = []
		via.append(spring[0])
		spring.pop(0)
		while len(spring) > 0:
			if spring[0]['x'] in range(min(dist['x'],via[-1]['x']),max(dist['x'],via[-1]['x'])+1):
				if spring[0]['y'] in range(min(dist['y'],via[-1]['y']),max(dist['y'],via[-1]['y'])+1):
					via.append(spring[0])
			spring.pop(0)

		path += (r*pi/2 - 2*r) * len(via)

print(path)

Submission status: Wrong Answer

Solution code:
import math

x1, y1, x2, y2 = map(int, input().split())
if x1 > x2:
	_x, _y = x2, y2
	x2, y2 = x1, y1
	x1, y1 = _x, _y

n = int(input())
f_list = []
for i in range(n):
	f_list.append(tuple(map(int, input().split())))

f_cnt = 0
_x1, _y1 = x1, y1
for i in range(n):
	x, y = f_list[i]
	if (_x1 <= x and x <= x2) and (_y1 <= y and y <= y2):
		f_cnt += 1
		#print(i, x, x1, x2, y, y1, y2)
		_x1, _y1 = x, y
dist = ((x2-x1) + abs(y2-y1)) * 100
if f_cnt > 0:
	if x2-x1 == 0 or y2-y1 == 0:
		delta = 10 * math.pi # 5 = 2 * 10 * 1/2
		dist += delta - 20
	else:
		delta = 5 * math.pi # 5 = 2 * 10 * 1/4
		dist += 20 - delta

print("%.11f" % dist)