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 sys
import math
def link( pool, f):
    def subset( a, b):
        return a[0] > b[0] and a[1] > b[0]
    notsubset = []
    max_value = 0
    for n,p in enumerate(pool): ##(X, Y, V)
        if subset(p[:2], f):
            max_value = max(max_value, p[2])
        else:
            notsubset.append(n)
    new_pool = [ pool[i] for i in notsubset]
    new_pool.append(
        f + [max_value + 1]
    )
    return new_pool
def orderit( fountains):
    return sorted( fountains, key=lambda x: max( x[0], x[1]), reverse=True)
def removeRedundant( fountains):
    return filter( lambda f:
        f if f[0] >= goal['x1'] and 
        f[0] <= goal['x2'] and
        f[1] >= goal['y1'] and
        f[1] <= goal['y2'] else None,
        fountains)
def transform( goal, fountains):
    if goal['x1'] > goal['x2']:
        goal['x1'] = -goal['x1']
        goal['x2'] = -goal['x2']
        for f in fountains:
            f[0] = -f[0]
    if goal['y1'] > goal['y2']:
        goal['y1'] = -goal['y1']
        goal['y2'] = -goal['y2']
        for f in fountains:
            f[1] = -f[1]
    return goal, fountains
def count_max( pool):
    if not pool:
        return 0
    return max( map( lambda x: x[2], pool))
def travel( goal, fcount):
    def special_case(goal, fcount):
        return fcount == 1 and( goal['x1'] == goal['x2'] or goal['y1'] ==
        goal['y2'])
    r = 10
    res = 100 *( goal['x2'] - goal['x1'] + goal['y2'] - goal['y1'] )
    if special_case(goal, fcount):
        res += fcount * (math.pi* 10 - 20)
    else:
        res += fcount * (  math.pi * 5 - 20 )
    return res
        
a,b,c,d = map(int, sys.stdin.readline().strip().split())
goal = {
    'x1': a,
    'y1': b,
    'x2': c,
    'y2': d,
}
N = int(sys.stdin.readline().strip())
fountains = []
for i in xrange(N):
    fountains.append(
        map( int, sys.stdin.readline().strip().split() )
    )
goal, fountains = transform( goal, fountains)
fountains = removeRedundant( fountains)
fountains = orderit( fountains)
pool = []
for f in fountains:
    pool = link(pool, f)
print  travel( goal, count_max(pool))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from math import pi

# 그냥 가면 100(|x1 - x2| + |y1 - y2|)
# junction 통과할 때마다 답이 좋아짐. 이 개수를 늘려야?
C = 100
J = -20 + pi * 2*10/4

x1, y1, x2, y2 = map(int, stdin.readline().split())
N = int(stdin.readline())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, stdin.readline().split())

for i in range(N):
    if x1 > x2: x[i] = int(1e8) - x[i]
    if y1 > y2: y[i] = int(1e8) - y[i]

if x1 > x2: x1, x2 = int(1e8) - x1, int(1e8) - x2
if y1 > y2: y1, y2 = int(1e8) - y1, int(1e8) - y2

ans = 0
P = [(x[i], y[i]) for i in range(N) if x1 <= x[i] <= x2 and y1 <= y[i] <= y2]
if x1 == x2 or y1 == y2:
    ans = C * (x2 - x1 + y2 - y1) + (-20 + 10*pi) * len(P)
elif len(P) == 0:
    ans = C * (x2 - x1 + y2 - y1)
elif len(P) > 0:
    P.sort()
    # y LIS
    import bisect
    cur = [P[0][1]]
    for x, y in P[1:]:
        if cur[-1] < y:
            cur.append(y)
        elif y < cur[0]:
            cur = [y]
        else:
            cur[bisect.bisect_left(cur, y)] = y
    ans = C * (x2 - x1 + y2 - y1) + J * len(cur)
print("%.20f" % ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

x1,y1,x2,y2= map(int, raw_input().split())
yinv=1
if x2<x1:
    [x1,y1,x2,y2]=[x2,y2,x1,y1]
if y2<y1:
    yinv=-1
y1*=yinv
y2*=yinv

N=int(raw_input())
F=[(x1,y1),(x2,y2)]
for i in range(N):
    Fx=map(int, raw_input().split())
    Fx[1] *= yinv
    if (Fx[0]>=x1 and Fx[0]<=x2) and (Fx[1]>=y1 and Fx[1]<=y2):
        F.append( tuple(Fx) )
F.sort(key=lambda x: sum(x))

FX=sorted([(x,x[0]) for x in F],key=lambda x:x[1])
FXk=[x[1] for x in FX]
FY=sorted([(x,x[1]) for x in F],key=lambda x:x[1])
FYk=[x[1] for x in FY]

N=len(F)
G={}
fnum=0
for f in F:
    G[f]=0
for i in range(N):
    f=F[i]
    if f != (x1, y1) and f!=(x2,y2):
#        X=FX[bisect.bisect_left(FXk[:],f[0])-1][0]
#        Y=FY[bisect.bisect_left(FYk[:],f[1])-1][0]
        X=(x1,y1)
        Y=(x1,y1)
        xind=bisect.bisect_left(FXk[:],f[0])-1
        for jj in range(0,xind):
            kk=xind-jj-1
            ii=-(N-kk)
            if FX[ii][0][1]<=f[1]:
                X=FX[ii][0]
                break
        yind=bisect.bisect_left(FYk[:],f[1])-1
        for jj in range(0,yind):
            kk=yind-jj-1
            ii=-(N-kk)
            if FY[ii][0][0]<=f[0]:
                Y=FY[ii][0]
                break
        XX=(G[X],X)
        YY=(G[Y],Y)
        bestf = max(XX,YY,key=lambda x: x[0])[1]
        G[f]=G[bestf]+1
        fnum=max(fnum,G[f])
delta=2*10-math.pi/2*10
ans=((y2-y1)+(x2-x1))*100-delta*fnum
print ans

Submission status: Wrong Answer

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import math
import copy

p = raw_input()
p = p.split()
p = map(int,p)

n = raw_input()
n = int(n)

x_min = min(p[0],p[2])
x_max = max(p[0],p[2])
y_min = min(p[1],p[3])
y_max = max(p[1],p[3])

if (p[0]-p[2])*(p[1]-p[3]) >= 0:
    status = 0
else:
    status = 1

funsui = []
for i in range(n):
    f = raw_input()
    f = f.split()
    f = map(int,f)
    if f[0] >= x_min and f[0] <= x_max and f[1] >= y_min and f[1] <= y_max:
        funsui.append(f)

funsui.sort()
count = 0
best = 0
last_y = 0

for f in funsui:
    if status == 0 and f[1] > last_y:
        count += 1
    elif status == 1 and f[1] < last_y:
        count += 1
    else:
        count = 1
    best = max(best,count)
    last_y = f[1]
    #print f,count

#print best
en = copy.copy(best)

if en > min((x_max-x_min),(y_max-y_min)):
    en += 1

ans = ((x_max-x_min) + (y_max-y_min)) * 100
ans -= 20 * best
ans += math.pi*5*en

print("%.12f" % (ans))

Submission status: Wrong Answer

Solution code:
import bisect
import math

x1,y1,x2,y2= map(int, raw_input().split())
yinv=1
if x2<x1:
    [x1,y1,x2,y2]=[x2,y2,x1,y1]
if y2<y1:
    yinv=-1
y1*=yinv
y2*=yinv

N=int(raw_input())
F=[(x1,y1),(x2,y2)]
for i in range(N):
    Fx=map(int, raw_input().split())
    Fx[1] *= yinv
    if (Fx[0]>=x1 and Fx[0]<=x2) and (Fx[1]>=y1 and Fx[1]<=y2):
        F.append( tuple(Fx) )
F.sort(key=lambda x: sum(x))

FX=sorted([(x,x[0]) for x in F],key=lambda x:x[1])
FXk=[x[1] for x in FX]
FY=sorted([(x,x[1]) for x in F],key=lambda x:x[1])
FYk=[x[1] for x in FY]

N=len(F)
G={}
fnum=0
for f in F:
    G[f]=0
for i in range(N):
    f=F[i]
    if f != (x1, y1) and f!=(x2,y2):
#        X=FX[bisect.bisect_left(FXk[:],f[0])-1][0]
#        Y=FY[bisect.bisect_left(FYk[:],f[1])-1][0]
        X=(x1,y1)
        Y=(x1,y1)
        xind=bisect.bisect_left(FXk[:],f[0])-1
        for jj in range(0,xind):
            kk=xind-jj-1
            ii=-(N-kk)
            if FX[ii][0][1]<=f[1]:
                X=FX[ii][0]
                break
        yind=bisect.bisect_left(FYk[:],f[1])-1
        for jj in range(0,yind):
            kk=yind-jj-1
            ii=-(N-kk)
            if FY[ii][0][0]<=f[0]:
                Y=FY[ii][0]
                break
        XX=(G[X],X)
        YY=(G[Y],Y)
        bestf = max(XX,YY,key=lambda x: x[0])[1]
        print f,X,Y, bestf
        G[f]=G[bestf]+1
        fnum=max(fnum,G[f])
delta=2*10-math.pi/2*10
ans=((y2-y1)+(x2-x1))*100-delta*fnum
print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect_right, insort
from collections import deque
from math import pi

def inpl(): return tuple(map(int, input().split()))
sx, sy, gx, gy = inpl()

N = int(input())
fountains = []
for _ in range(N):
    x, y = inpl()
    if sy > gy:
        y = 10**8 - 1 - y
    insort(fountains, [x, y])

if sx > gx:
    sx, sy, gx, gy = gx, gy, sx, sy
if sy > gy:
    sy, gy = 10**8 - 1 - sy, 10**8 - 1 - gy 

fl = bisect_left(fountains, [sx, sy])
fr = bisect_right(fountains, [gx, gy])

fount = fountains[fl:fr]


que = deque([[0, sx, sy]])
res = 0
while que:
    count_, tx, ty = que.pop()
    tfl = bisect_left(fountains, [tx, sy])
    
    for fount in fountains[tfl:fr]:
        if (fount[1] > ty) & (fount[1] <= gy):
            que.appendleft([count_+1, fount[0], fount[1]])

    if tx != fountains[fr-1][0]:
        while tfl < fr-1:
            if fountains[tfl+1][1] > ty:
                que.appendleft([count_, fountains[tfl+1][0], fountains[tfl+1][1]])
                break
            tfl += 1
    res = max(res, count_)


if (gx != sx) & (gy != sy):
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*res)
else:
    fx, fy = fountains[fl]
    if (fx == sx) or (fy == sy):
        print((((gx - sx)+(gy - sy))*100 + (10*pi - 20)))
    else:
        print((((gx - sx)+(gy - sy))*100))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def II(): return int(input())
def ILI(): return list(map(int, input().split()))

PI = math.pi
kado = 5 * PI - 20
choku = 10 * PI - 20


def read():
    x_1, y_1, x_2, y_2 = ILI()
    x_1, x_2 = min(x_1, x_2), max(x_1, x_2)
    y_1, y_2 = min(y_1, y_2), max(y_1, y_2)
    N = II()
    points = []
    for __ in range(N):
        x, y = ILI()
        if x_1 <= x <= x_2 and y_1 <= y <= y_2:
            points.append((x, y))
    return x_1, y_1, x_2, y_2, N, points


def solve(x_1, y_1, x_2, y_2, N, points):
    x_dif = x_2 - x_1
    y_dif = y_2 - y_1
    if len(points) == 0:
        ans = (x_dif + y_dif) * 100
    else:
        points.sort(key=lambda x: x[0])
        count = [1] * len(points)
        for i in range(len(points) - 1, -1, -1):
            for j in range(i + 1, len(points)):
                if points[i][1] < points[j][1]:
                    count[i] = max(count[i], count[j] + 1)
        max_count = max(count)
        if max_count - 1 == x_dif or max_count - 1 == y_dif:
            ans = (x_dif + y_dif) * 100 + (max_count - 1) * kado + choku
        else:
            ans = (x_dif + y_dif) * 100 + max_count * kado
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# C
import numpy as np

x1, y1, x2, y2 = map(int, input().split())
N = int(input())

xL = min(x1, x2)
xR = max(x1, x2)
yL = min(y1, y2)
yR = max(y1, y2)

xv = np.zeros(N, dtype='int')
yv = np.zeros(N, dtype='int')

ind = 0
for _ in range(N):
    x, y = map(int, input().split())
    if xL <= x and x <= xR and yL <= y and y <= yR:
        xv[ind] = x
        yv[ind] = y
        ind += 1

xv = xv[:ind]
yv = yv[:ind]

N = ind



if x1 < x2 and y1 > y2:
    direction = 'upper'
elif x1 > x2 and y1 < y2:
    direction = 'upper'
else:
    direction = 'down'

    
# sort
xv_s = np.argsort(xv)
yv_ = yv[xv_s]

if direction == 'upper':
    yv_s = np.argsort(-yv_)
else:
    yv_s = np.argsort(yv_)

# bit
K2 = 0
N2 = 1

while N2 < N:
    N2 *= 2
    K2 += 1

# segtree
SGT = []
for k in range(K2+1):
    SGT.append([0] * (N2 // (2**k)))

# update
def update(i, a):
    global SGT
    j = i
    SGT[0][j] = a
    for k in range(1, K2+1):
        j = j // 2
        SGT[k][j] = max(SGT[k-1][2*j], SGT[k-1][2*j+1])
        
# query [a, b)
def query_max(a, b, k=K2, l=0, r=N2):
    if r <= a or b <= l:
        return 0
    elif a <= l and r <= b:
        return SGT[k][l // (2**k)]
    else:
        vl = query_max(a, b, k-1, l, (l+r)//2)
        vr = query_max(a, b, k-1, (l+r)//2, r)
        return max(vl, vr)
    

# calculate
for i in range(N):
    l = query_max(0, yv_s[i])
    update(i, l+1)
    
count_ = query_max(0, N+1)

diff = 5*np.pi - 20
diff2 = 10*np.pi - 20
if count_ == min((xR-xL), (yR-yL)) + 1:
    print(100*((xR-xL) + (yR-yL)) + (count_-1)*diff + diff2)
else:
    print(100*((xR-xL) + (yR-yL)) + count_*diff)

Submission status: Wrong Answer

Solution code:
import sys
import math
def link( pool, f):
    def subset( a, b):
        return a[0] > b[0] and a[1] > b[0]
    notsubset = []
    max_value = 0
    for n,p in enumerate(pool): ##(X, Y, V)
        if subset(p[:2], f):
            max_value = max(max_value, p[2])
        else:
            notsubset.append(n)
    new_pool = [ pool[i] for i in notsubset]
    new_pool.append(
        f + [max_value + 1]
    )
    return new_pool
def orderit( fountains):
    return sorted( fountains, key=lambda x: max( x[0], x[1]), reverse=True)
def removeRedundant( fountains):
    return filter( lambda f:
        f if f[0] >= goal['x1'] and 
        f[0] <= goal['x2'] and
        f[1] >= goal['y1'] and
        f[1] <= goal['y2'] else None,
        fountains)
def transform( goal, fountains):
    if goal['x1'] > goal['x2']:
        goal['x1'] = -goal['x1']
        goal['x2'] = -goal['x2']
        for f in fountains:
            f[0] = -f[0]
    if goal['y1'] > goal['y2']:
        goal['y1'] = -goal['y1']
        goal['y2'] = -goal['y2']
        for f in fountains:
            f[1] = -f[1]
    return goal, fountains
def count_max( pool):
    print pool
    if not pool:
        return 0
    return max( map( lambda x: x[2], pool))
def travel( goal, fcount):
    def special_case(goal, fcount):
        return fcount == 1 and( goal['x1'] == goal['x2'] or goal['y1'] ==
        goal['y2'])
    r = 10
    res = 100 *( goal['x2'] - goal['x1'] + goal['y2'] - goal['y1'] )
    if special_case(goal, fcount):
        res += fcount * (math.pi* 10 - 20)
    else:
        res += fcount * (  math.pi * 5 - 20 )
    return res
        
a,b,c,d = map(int, sys.stdin.readline().strip().split())
goal = {
    'x1': a,
    'y1': b,
    'x2': c,
    'y2': d,
}
N = int(sys.stdin.readline().strip())
fountains = []
for i in xrange(N):
    fountains.append(
        map( int, sys.stdin.readline().strip().split() )
    )
goal, fountains = transform( goal, fountains)
fountains = removeRedundant( fountains)
fountains = orderit( fountains)
pool = []
for f in fountains:
    pool = link(pool, f)

print travel( goal, count_max(pool))

Submission status: Wrong Answer

Solution code:
from math import pi
import decimal


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def get_max(self, i):
        s = 0
        while i > 0:
            s = max(s, self.tree[i])
            i -= i & -i
        return s

    def update(self, i, x):
        while i <= self.size:
            self.tree[i] = max(self.tree[i], x)
            i += i & -i


def solve():
    x1, y1, x2, y2 = map(int, input().split())
    if x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    is_down = y1 > y2
    if is_down:
        y1, y2 = -y1, -y2

    n = int(input())
    fountains = []
    for _ in range(n):
        x, y = map(int, input().split())
        if is_down:
            y = -y
        if x < x1 or x2 < x or y < y1 or y2 < y:
            continue
        fountains.append((y, x))
    fountains.sort()

    if x1 == x2:
        base = (y2 - y1) * 100
        for y, x in fountains:
            if x == x1:
                if y1 < y < y2:
                    return base + 10 * pi - 20
                else:
                    break
        return base
    if y1 == y2:
        base = (x2 - x1) * 100
        for y, x in fountains:
            if y == y1:
                if x1 < x < x2:
                    return base + 10 * pi - 20
                else:
                    break
        return base

    uncmp_x = sorted({x1, x2}.union(f[1] for f in fountains))
    cmp_x = {x: i for i, x in enumerate(uncmp_x)}

    dp = Bit(n + 2)
    for y, x in fountains:
        x = cmp_x[x]
        dp.update(x + 1, dp.get_max(x) + 1)

    mc = dp.get_max(n + 2)
    dpi = decimal.Decimal(pi)
    base = decimal.Decimal((x2 - x1 + y2 - y1) * 100 - mc * 20)

    return str(base + mc * 5 * dpi)


print(solve())

Submission status: Wrong Answer

Solution code:
# C
import numpy as np

x1, y1, x2, y2 = map(int, input().split())
N = int(input())

xL = min(x1, x2)
xR = max(x1, x2)
yL = min(y1, y2)
yR = max(y1, y2)

xv = np.zeros(N, dtype='int')
yv = np.zeros(N, dtype='int')

ind = 0
for _ in range(N):
    x, y = map(int, input().split())
    if xL <= x and x <= xR and yL <= y and y <= yR:
        xv[ind] = x
        yv[ind] = y
        ind += 1

xv = xv[:ind]
yv = yv[:ind]

N = ind



if x1 < x2 and y1 > y2:
    direction = 'upper'
elif x1 > x2 and y1 < y2:
    direction = 'upper'
else:
    direction = 'down'

    
# sort
xv_s = np.argsort(xv)
yv_ = yv[xv_s]

if direction == 'upper':
    yv_s = np.argsort(-yv_)
else:
    yv_s = np.argsort(yv_)

# bit
K2 = 0
N2 = 1

while N2 < N:
    N2 *= 2
    K2 += 1

# segtree
SGT = []
for k in range(K2+1):
    SGT.append([0] * (N2 // (2**k)))

# update
def update(i, a):
    global SGT
    j = i
    SGT[0][j] = a
    for k in range(1, K2+1):
        j = j // 2
        SGT[k][j] = max(SGT[k-1][2*j], SGT[k-1][2*j+1])
        
# query [a, b)
def query_max(a, b, k=K2, l=0, r=N2):
    if r <= a or b <= l:
        return 0
    elif a <= l and r <= b:
        return SGT[k][l // (2**k)]
    else:
        vl = query_max(a, b, k-1, l, (l+r)//2)
        vr = query_max(a, b, k-1, (l+r)//2, r)
        return max(vl, vr)
    

# calculate
for i in range(N):
    l = query_max(0, yv_s[i])
    update(i, l+1)
    
count_ = query_max(0, N+1)

diff = 5*np.pi - 20

print(100*((xR-xL) + (yR-yL)) + count_*diff)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def II(): return int(input())
def ILI(): return list(map(int, input().split()))

PI = math.pi
kado = 5 * PI - 20
choku = 10 * PI - 20


def read():
    x_1, y_1, x_2, y_2 = ILI()
    x_1, x_2 = min(x_1, x_2), max(x_1, x_2)
    y_1, y_2 = min(y_1, y_2), max(y_1, y_2)
    N = II()
    points = []
    for __ in range(N):
        x, y = ILI()
        if x_1 <= x <= x_2 and y_1 <= y <= y_2:
            points.append((x, y))
    return x_1, y_1, x_2, y_2, N, points


def solve(x_1, y_1, x_2, y_2, N, points):
    if len(points) == 0:
        ans = ((x_2 - x_1) + (y_2 - y_1)) * 100
    else:
        x_dif = x_2 - x_1
        y_dif = y_2 - y_1
        if x_dif == 0:
            ans = y_dif * 100
            for p in points:
                if p[0] == x_1:
                    ans += choku
                    break
        elif y_dif == 0:
            ans = x_dif * 100
            for p in points:
                if p[1] == y_1:
                    ans += choku
                    break
        else:
            points.sort(key=lambda x: x[0])
            count = [1] * len(points)
            for i in range(len(points) - 1, -1, -1):
                for j in range(i + 1, len(points)):
                    if points[i][1] < points[j][1]:
                        count[i] = max(count[i], count[j] + 1)
            max_count = max(count)
            ans = (x_dif + y_dif) * 100 + max_count * kado
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
def link( pool, f):
    def subset( a, b):
        return a[0] > b[0] and a[1] > b[0]
    notsubset = []
    max_value = 0
    for n,p in enumerate(pool): ##(X, Y, V)
        if subset(p[:2], f):
            max_value = max(max_value, p[2])
        else:
            notsubset.append(n)
    new_pool = [ pool[i] for i in notsubset]
    new_pool.append(
        f + [max_value + 1]
    )
    return new_pool
def orderit( fountains):
    return sorted( fountains, key=lambda x: max( x[0], x[1]), reverse=True)
def removeRedundant( fountains):
    return filter( lambda f:
        f if f[0] >= goal['x1'] and 
        f[0] <= goal['x2'] and
        f[1] >= goal['y1'] and
        f[1] <= goal['y2'] else None,
        fountains)
def transform( goal, fountains):
    if goal['x1'] > goal['x2']:
        goal['x1'] = -goal['x1']
        goal['x2'] = -goal['x2']
        for f in fountains:
            f[0] = -f[0]
    if goal['y1'] > goal['y2']:
        goal['y1'] = -goal['y1']
        goal['y2'] = -goal['y2']
        for f in fountains:
            f[1] = -f[1]
    return goal, fountains
def count_max( pool):
    print pool
    if not pool:
        return 0
    return max( map( lambda x: x[2], pool))
def travel( goal, fcount):
    r = 10
    res = 100 *( goal['x2'] - goal['x1'] + goal['y2'] - goal['y1'] )
    res += fcount * (  math.pi * 5 - 20 )
    return res
        
a,b,c,d = map(int, sys.stdin.readline().strip().split())
goal = {
    'x1': a,
    'y1': b,
    'x2': c,
    'y2': d,
}
N = int(sys.stdin.readline().strip())
fountains = []
for i in xrange(N):
    fountains.append(
        map( int, sys.stdin.readline().strip().split() )
    )
goal, fountains = transform( goal, fountains)
fountains = removeRedundant( fountains)
fountains = orderit( fountains)
pool = []
for f in fountains:
    pool = link(pool, f)
print travel( goal, count_max(pool))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def II(): return int(input())
def ILI(): return list(map(int, input().split()))

PI = math.pi
kado = 5 * PI - 20
choku = 10 * PI - 20


def read():
    x_1, y_1, x_2, y_2 = ILI()
    x_1, x_2 = min(x_1, x_2), max(x_1, x_2)
    y_1, y_2 = min(y_1, y_2), max(y_1, y_2)
    N = II()
    points = []
    for __ in range(N):
        x, y = ILI()
        if x_1 <= x <= x_2 and y_1 <= y <= y_2:
            points.append((x, y))
    return x_1, y_1, x_2, y_2, N, points


def solve(x_1, y_1, x_2, y_2, N, points):
    if len(points) == 0:
        ans = ((x_2 - x_1) + (y_2 - y_1)) * 100
    else:
        x_dif = x_2 - x_1
        y_dif = y_2 - y_1
        if x_dif == 0:
            ans = y_dif * 100
            for p in points:
                if p[0] == x_1:
                    ans += choku
                    break
        elif y_dif == 0:
            ans = x_dif * 100
            for p in points:
                if p[1] == y_1:
                    ans += choku
                    break
        else:
            count = [1] * len(points)
            for i in range(len(points) - 1, -1, -1):
                for j in range(i + 1, len(points)):
                    if points[i][1] < points[j][1]:
                        count[i] = max(count[i], count[j] + 1)
            max_count = max(count)
            ans = (x_dif + y_dif) * 100 + max_count * kado
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import math
import copy

p = raw_input()
p = p.split()
p = map(int,p)

n = raw_input()
n = int(n)

x_min = min(p[0],p[2])
x_max = max(p[0],p[2])
y_min = min(p[1],p[3])
y_max = max(p[1],p[3])

funsui = []
for i in range(n):
    f = raw_input()
    f = f.split()
    f = map(int,f)
    if f[0] >= x_min and f[0] <= x_max and f[1] >= y_min and f[1] <= y_max:
        funsui.append(f)

funsui.sort()
count = 0
best = 0
last_y = 0

for f in funsui:
    if f[1] > last_y:
        count += 1
    else:
        count = 1
    best = max(best,count)
    last_y = f[1]
    #print f,count

#print best
en = copy.copy(best)

if en > min((x_max-x_min),(y_max-y_min)):
    en += 1

ans = ((x_max-x_min) + (y_max-y_min)) * 100
ans -= 20 * best
ans += math.pi*5*en

print("%.12f" % (ans))

Submission status: Wrong Answer

Solution code:
import sys
import math 
x1,y1,x2,y2=map(int,input().split())
N=int(input())
XY=[list(map(int,input().split())) for _ in range(N)]
pi=math.pi
short=20-5*pi
long=10*pi-20
fountain=0
straight=100*(abs(x1-x2)+abs(y1-y2))
 
if x1==x2:
  for i in range(N):
    if XY[i][0]==x1: fountain+=1
  print(straight+long*fountain)
  sys.exit()
if y1==y2:
  for i in range(N):
    if XY[i][1]==x1: fountain+=1
  print(straight+long*fountain)
  sys.exit()
print(straight-short*fountain)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

def II(): return int(input())
def ILI(): return list(map(int, input().split()))

PI = math.pi


def read():
    x_1, y_1, x_2, y_2 = ILI()
    x_1, x_2 = min(x_1, x_2), max(x_1, x_2)
    y_1, y_2 = min(y_1, y_2), max(y_1, y_2)
    N = II()
    points = []
    for __ in range(N):
        x, y = ILI()
        if x_1 <= x <= x_2 and y_1 <= y <= y_2:
            points.append((x, y))
    return x_1, y_1, x_2, y_2, N, points


def solve(x_1, y_1, x_2, y_2, N, points):
    if len(points) == 0:
        ans = ((x_2 - x_1) + (y_2 - y_1)) * 100
    else:
        count = [1] * len(points)
        for i in range(len(points) - 1, -1, -1):
            for j in range(i + 1, len(points)):
                if points[i][1] < points[j][1]:
                    count[i] = max(count[i], count[j] + 1)
        max_count = max(count)
        x_dif = x_2 - x_1
        y_dif = y_2 - y_1
        if x_dif + 1 == max_count or y_dif + 1 == max_count:
            ans = (x_dif + y_dif) * 100 + (max_count - 1) * (5 * PI - 20) + (10 * PI - 20)
        else:
            ans = (x_dif + y_dif) * 100 + (max_count - 1) * (5 * PI - 20)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
sx,sy,gx,gy = list(map(int,input().split()))
n = int(input())
h = [0]*n
for i in range(n):
    h[i] = list(map(int,input().split()))
rx = 0
ry = 0
X = sx - 1
Y = sy - 1
if gx - sx <0:
    rx = 1
    X = sx + 1
if gy - sy < 0:
    ry = 1
    Y = sy + 1
_Y = Y

dp = [[0 for i in range(abs(sy-gy)+2)]for j in range(abs(sx-gx)+2)]
for i in range(0,abs(sx-gx)+2):
    if rx == 1:
        x = X - i
    else:
        x = X + i
    Y = _Y
    for j in range(0,abs(sy-gy)+2):
        if ry == 1:
            y = Y - j
        else:
            y = Y + j
        if(i == 0 or j== 9):
            continue
        for k in range(n):
            if h[k][0] == x and h[k][1] == y:
                dp[i][j] += 1
        dp[i][j] = max(dp[i-1][j]+dp[i][j], dp[i][j-1]+dp[i][j])

a = max(dp[len(dp)-1])



ans = (abs(sx-gx) + abs(sy-gy) )* 100
ans -= a*20
ans += a*(20 * math.pi/4)
if(sx==gx or sy == gy):
    ans += 20*math.pi/4
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math 
x1,y1,x2,y2=map(int,input().split())
N=int(input())
XY=[list(map(int,input().split())) for _ in range(N)]
print(XY)
pi=math.pi
short=20-5*pi
long=10*pi-20
fountain=0
straight=100*(abs(x1-x2)+abs(y1-y2))

if x1==x2:
  for i in range(N):
    if XY[i][0]==x1: fountain+=1
  print(straight+long*fountain)
  sys.exit()
if y1==y2:
  for i in range(N):
    if XY[i][1]==x1: fountain+=1
  print(straight+long*fountain)
  sys.exit()
print(straight-short*fountain)

Submission status: Wrong Answer

Solution code:
from math import pi


def solve():
    x1, y1, x2, y2 = map(int, input().split())
    if x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    is_down = y1 > y2
    if is_down:
        y1, y2 = -y1, -y2

    n = int(input())
    fountains = []
    for _ in range(n):
        x, y = map(int, input().split())
        if is_down:
            y = -y
        if x < x1 or x2 < x or y < y1 or y2 < y:
            continue
        fountains.append((y, x))
    fountains.sort()

    if x1 == x2:
        base = (y2 - y1) * 100
        for y, x in fountains:
            if x == x1:
                if y1 < y < y2:
                    return base + 10 * pi - 20
                else:
                    break
        return base
    if y1 == y2:
        base = (x2 - x1) * 100
        for y, x in fountains:
            if y == y1:
                if x1 < x < x2:
                    return base + 10 * pi - 20
                else:
                    break
        return base

    uncmp_x = sorted({x1, x2}.union(f[1] for f in fountains))
    uncmp_y = sorted({y1, y2}.union(f[0] for f in fountains))
    cmp_x = {x: i for i, x in enumerate(uncmp_x)}
    cmp_y = {y: i for i, y in enumerate(uncmp_y)}
    fountains = [(cmp_y[y], cmp_x[x]) for y, x in fountains]

    dp = [0] * (n + 2)
    for y, x in fountains:
        dp[x] = max(dp[:x], default=0) + 1

    mc = max(dp)
    return (x2 - x1 + y2 - y1) * 100 - mc * 20 + mc * 5 * pi


print(solve())