結果

問題 No.2376 障害物競プロ
ユーザー mkawa2mkawa2
提出日時 2023-07-08 11:19:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,968 ms / 4,000 ms
コード長 3,389 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 90,828 KB
最終ジャッジ日時 2024-07-26 15:12:02
合計ジャッジ時間 84,310 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,376 KB
testcase_01 AC 43 ms
53,632 KB
testcase_02 AC 44 ms
53,888 KB
testcase_03 AC 43 ms
53,632 KB
testcase_04 AC 363 ms
78,280 KB
testcase_05 AC 634 ms
81,868 KB
testcase_06 AC 541 ms
82,572 KB
testcase_07 AC 921 ms
85,140 KB
testcase_08 AC 909 ms
83,692 KB
testcase_09 AC 888 ms
85,284 KB
testcase_10 AC 962 ms
84,032 KB
testcase_11 AC 1,061 ms
87,552 KB
testcase_12 AC 998 ms
87,460 KB
testcase_13 AC 900 ms
83,060 KB
testcase_14 AC 937 ms
83,116 KB
testcase_15 AC 910 ms
83,396 KB
testcase_16 AC 942 ms
84,588 KB
testcase_17 AC 1,137 ms
88,472 KB
testcase_18 AC 1,011 ms
86,700 KB
testcase_19 AC 3,968 ms
89,936 KB
testcase_20 AC 3,701 ms
89,808 KB
testcase_21 AC 3,731 ms
90,828 KB
testcase_22 AC 789 ms
83,804 KB
testcase_23 AC 675 ms
83,148 KB
testcase_24 AC 301 ms
76,672 KB
testcase_25 AC 363 ms
80,880 KB
testcase_26 AC 327 ms
76,672 KB
testcase_27 AC 498 ms
81,804 KB
testcase_28 AC 573 ms
83,604 KB
testcase_29 AC 437 ms
82,364 KB
testcase_30 AC 594 ms
84,704 KB
testcase_31 AC 530 ms
84,124 KB
testcase_32 AC 381 ms
82,040 KB
testcase_33 AC 466 ms
83,044 KB
testcase_34 AC 482 ms
83,304 KB
testcase_35 AC 144 ms
76,928 KB
testcase_36 AC 739 ms
84,632 KB
testcase_37 AC 716 ms
83,396 KB
testcase_38 AC 493 ms
82,576 KB
testcase_39 AC 802 ms
84,140 KB
testcase_40 AC 599 ms
84,308 KB
testcase_41 AC 461 ms
82,764 KB
testcase_42 AC 3,174 ms
86,276 KB
testcase_43 AC 3,444 ms
86,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(1000005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# md = 10**9+7
md = 998244353

def ccw(s, t, p):
    x1 = p[0]-s[0]
    y1 = p[1]-s[1]
    x2 = t[0]-s[0]
    y2 = t[1]-s[1]
    if x1*y2-x2*y1 > 0: return 1
    if x1*y2-x2*y1 < 0: return -1
    if x1*x2+y1*y2 < 0: return -2
    if x1**2+y1**2 > x2**2+y2**2: return 2
    return False

# 共有点の有無のみ
def common_point(a, b, s, t):
    cc = []
    cc.append(ccw(a, b, s))
    cc.append(ccw(a, b, t))
    cc.append(ccw(s, t, a))
    cc.append(ccw(s, t, b))
    if any(c == 0 for c in cc): return True
    if any(abs(c) == 2 for c in cc): return False
    if cc[0] == cc[1] or cc[2] == cc[3]: return False
    return True

# co = 10**10

n, m = LI()
xy, st = [], []
for _ in range(n):
    x, y, s, t = LI()
    # xy.append((x*co, y*co))
    # st.append((s*co, t*co))
    xy.append((x, y))
    st.append((s, t))

dist = [[inf]*2*n for _ in range(2*n)]

def can(a, b, i, j):
    for k in range(n):
        if k == i or k == j: continue
        if common_point(a, b, xy[k], st[k]): return False
    return True

for i in range(n):
    dist[i*2][i*2] = 0
    dist[i*2+1][i*2+1] = 0
    if can(xy[i], st[i], i, i):
        x, y = xy[i]
        s, t = st[i]
        # dist[i*2][i*2+1] = dist[i*2+1][i*2] = round(((s-x)**2+(t-y)**2)**0.5)
        dist[i*2][i*2+1] = dist[i*2+1][i*2] = ((s-x)**2+(t-y)**2)**0.5
    for j in range(i):
        if can(xy[i], xy[j], i, j):
            x, y = xy[i]
            s, t = xy[j]
            # dist[i*2][j*2] = dist[j*2][i*2] = round(((s-x)**2+(t-y)**2)**0.5)
            dist[i*2][j*2] = dist[j*2][i*2] = ((s-x)**2+(t-y)**2)**0.5
        if can(xy[i], st[j], i, j):
            x, y = xy[i]
            s, t = st[j]
            # dist[i*2][j*2+1] = dist[j*2+1][i*2] = round(((s-x)**2+(t-y)**2)**0.5)
            dist[i*2][j*2+1] = dist[j*2+1][i*2] = ((s-x)**2+(t-y)**2)**0.5
        if can(st[i], xy[j], i, j):
            x, y = st[i]
            s, t = xy[j]
            # dist[i*2+1][j*2] = dist[j*2][i*2+1] = round(((s-x)**2+(t-y)**2)**0.5)
            dist[i*2+1][j*2] = dist[j*2][i*2+1] = ((s-x)**2+(t-y)**2)**0.5
        if can(st[i], st[j], i, j):
            x, y = st[i]
            s, t = st[j]
            # dist[i*2+1][j*2+1] = dist[j*2+1][i*2+1] = round(((s-x)**2+(t-y)**2)**0.5)
            dist[i*2+1][j*2+1] = dist[j*2+1][i*2+1] = ((s-x)**2+(t-y)**2)**0.5
# p2D(dist)

for j in range(n*2):
    for i in range(n*2):
        ij = dist[i][j]
        if ij == inf: continue
        for k in range(n*2):
            jk = dist[j][k]
            if jk == inf: continue
            dist[i][k] = min(dist[i][k], ij+jk)

for _ in range(m):
    i, b, j, d = LI1()
    ans = dist[i*2+b][j*2+d]
    # print(ans/co)
    print(ans)
0