結果

問題 No.2376 障害物競プロ
ユーザー shogo314shogo314
提出日時 2023-07-07 23:03:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,055 ms / 4,000 ms
コード長 1,384 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 86,460 KB
実行使用メモリ 82,356 KB
最終ジャッジ日時 2023-09-29 00:45:59
合計ジャッジ時間 88,832 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,764 KB
testcase_01 AC 74 ms
71,580 KB
testcase_02 AC 76 ms
71,852 KB
testcase_03 AC 76 ms
71,388 KB
testcase_04 AC 634 ms
78,980 KB
testcase_05 AC 891 ms
80,096 KB
testcase_06 AC 604 ms
80,276 KB
testcase_07 AC 1,717 ms
80,904 KB
testcase_08 AC 1,767 ms
82,264 KB
testcase_09 AC 1,604 ms
81,732 KB
testcase_10 AC 1,578 ms
81,692 KB
testcase_11 AC 1,703 ms
81,056 KB
testcase_12 AC 1,614 ms
81,104 KB
testcase_13 AC 1,560 ms
80,572 KB
testcase_14 AC 1,600 ms
81,328 KB
testcase_15 AC 1,401 ms
80,452 KB
testcase_16 AC 1,590 ms
81,460 KB
testcase_17 AC 1,722 ms
81,764 KB
testcase_18 AC 1,716 ms
80,556 KB
testcase_19 AC 1,394 ms
81,444 KB
testcase_20 AC 1,943 ms
81,904 KB
testcase_21 AC 1,907 ms
82,356 KB
testcase_22 AC 1,243 ms
80,936 KB
testcase_23 AC 1,065 ms
81,008 KB
testcase_24 AC 589 ms
78,568 KB
testcase_25 AC 398 ms
78,820 KB
testcase_26 AC 650 ms
78,760 KB
testcase_27 AC 623 ms
79,380 KB
testcase_28 AC 674 ms
80,304 KB
testcase_29 AC 413 ms
79,452 KB
testcase_30 AC 862 ms
80,752 KB
testcase_31 AC 600 ms
79,596 KB
testcase_32 AC 270 ms
80,008 KB
testcase_33 AC 441 ms
79,772 KB
testcase_34 AC 476 ms
80,460 KB
testcase_35 AC 225 ms
78,208 KB
testcase_36 AC 1,254 ms
81,896 KB
testcase_37 AC 1,016 ms
80,468 KB
testcase_38 AC 480 ms
80,124 KB
testcase_39 AC 1,424 ms
80,888 KB
testcase_40 AC 954 ms
80,744 KB
testcase_41 AC 415 ms
79,516 KB
testcase_42 AC 2,055 ms
82,204 KB
testcase_43 AC 2,039 ms
81,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def intersect(p1, p2, p3, p4):
    tc1 = (p1[0] - p2[0]) * (p3[1] - p1[1]) + (p1[1] - p2[1]) * (p1[0] - p3[0])
    tc2 = (p1[0] - p2[0]) * (p4[1] - p1[1]) + (p1[1] - p2[1]) * (p1[0] - p4[0])
    td1 = (p3[0] - p4[0]) * (p1[1] - p3[1]) + (p3[1] - p4[1]) * (p3[0] - p1[0])
    td2 = (p3[0] - p4[0]) * (p2[1] - p3[1]) + (p3[1] - p4[1]) * (p3[0] - p2[0])
    return tc1*tc2 < 0 and td1*td2 < 0


N, M = map(int, input().split())
xyxy = [tuple(map(int, input().split())) for i in range(N)]


def dist(a, b, c, d):
    return ((xyxy[a][0+b*2]-xyxy[c][0+d*2])**2+(xyxy[a][1+b*2]-xyxy[c][1+d*2])**2)**0.5


w = [[10**18 for j in range(2*N)] for i in range(2*N)]
for i in range(2*N):
    for j in range(i, 2*N):
        if i == j:
            w[i][j] = 0
            continue
        a, b, c, d = i//2, i % 2, j//2, j % 2
        p1 = (xyxy[a][0+b*2], xyxy[a][1+b*2])
        p2 = (xyxy[c][0+d*2], xyxy[c][1+d*2])
        for k in range(N):
            p3 = (xyxy[k][0], xyxy[k][1])
            p4 = (xyxy[k][2], xyxy[k][3])
            if intersect(p1, p2, p3, p4):
                break
        else:
            w[i][j] = dist(a, b, c, d)
            w[j][i] = w[i][j]
for k in range(2*N):
    for i in range(2*N):
        for j in range(2*N):
            w[i][j]=min(w[i][j],w[i][k]+w[k][j])

for i in range(M):
    a,b,c,d=map(lambda x:int(x)-1,input().split())
    print(w[2*a+b][2*c+d])
0