結果

問題 No.2376 障害物競プロ
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-07-03 17:08:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,765 ms / 4,000 ms
コード長 1,548 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 81,480 KB
最終ジャッジ日時 2023-09-24 13:55:58
合計ジャッジ時間 93,949 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,088 KB
testcase_01 AC 72 ms
71,032 KB
testcase_02 AC 72 ms
71,252 KB
testcase_03 AC 71 ms
71,240 KB
testcase_04 AC 613 ms
78,632 KB
testcase_05 AC 824 ms
78,868 KB
testcase_06 AC 542 ms
79,528 KB
testcase_07 AC 1,715 ms
79,896 KB
testcase_08 AC 1,688 ms
80,044 KB
testcase_09 AC 1,763 ms
80,944 KB
testcase_10 AC 1,738 ms
80,964 KB
testcase_11 AC 1,743 ms
81,160 KB
testcase_12 AC 1,738 ms
81,480 KB
testcase_13 AC 1,575 ms
79,840 KB
testcase_14 AC 1,762 ms
80,660 KB
testcase_15 AC 1,574 ms
80,376 KB
testcase_16 AC 1,765 ms
80,476 KB
testcase_17 AC 1,715 ms
80,564 KB
testcase_18 AC 1,736 ms
81,348 KB
testcase_19 AC 1,379 ms
80,592 KB
testcase_20 AC 1,412 ms
79,908 KB
testcase_21 AC 1,411 ms
80,672 KB
testcase_22 AC 1,201 ms
79,628 KB
testcase_23 AC 1,119 ms
79,772 KB
testcase_24 AC 599 ms
78,408 KB
testcase_25 AC 413 ms
78,804 KB
testcase_26 AC 638 ms
78,468 KB
testcase_27 AC 632 ms
79,132 KB
testcase_28 AC 655 ms
79,744 KB
testcase_29 AC 410 ms
79,188 KB
testcase_30 AC 986 ms
79,832 KB
testcase_31 AC 564 ms
79,844 KB
testcase_32 AC 246 ms
79,004 KB
testcase_33 AC 468 ms
79,872 KB
testcase_34 AC 434 ms
80,012 KB
testcase_35 AC 240 ms
78,728 KB
testcase_36 AC 1,339 ms
79,912 KB
testcase_37 AC 947 ms
80,356 KB
testcase_38 AC 455 ms
79,068 KB
testcase_39 AC 1,472 ms
80,020 KB
testcase_40 AC 998 ms
80,056 KB
testcase_41 AC 413 ms
79,052 KB
testcase_42 AC 1,682 ms
79,776 KB
testcase_43 AC 1,701 ms
80,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    n, m = map(int, input().split())
    xy = [1+1j] * (n*2)
    for i in range(n):
        x0, y0, x1, y1 = map(int, input().split())
        xy[i*2] = x0 + y0*1j
        xy[i*2+1] = x1 + y1*1j

    def segment_intersect(p1, p2, q1, q2):
        p1s = ((q2-q1).conjugate()*(p1-q1)).imag
        p2s = ((q2-q1).conjugate()*(p2-q1)).imag
        q1s = ((p2-p1).conjugate()*(q1-p1)).imag
        q2s = ((p2-p1).conjugate()*(q2-p1)).imag
        if q1s == 0 and q2s == 0:
            return False
        if (((q1s > 0) - (q1s < 0)) == ((q2s > 0) - (q2s < 0))):
            return False
        if (((p1s > 0) - (p1s < 0)) == ((p2s > 0) - (p2s < 0))):
            return False
        return True

    dist = [[1e9] * (n*2) for _ in range(n*2)]
    for i in range(n*2):
        for j in range(n*2):
            if i == j:
                dist[i][j] = 0
                continue
            if ((i>>1) == (j>>1)):
                continue
            ok = True
            for k in range(n):
                if(k == (i>>1) or k == (j>>1)):
                    continue
                ok &= not(segment_intersect(xy[i], xy[j], xy[k*2], xy[k*2+1]))
            if ok:
                dist[i][j] = abs(xy[i]-xy[j])
    for k in range(n*2):
        for i in range(n*2):
            for j in range(n*2):
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
    for _ in range(m):
        a, b, c, d = map(int, input().split())
        a -= 1
        b -= 1
        c -= 1
        d -= 1
        print(dist[a*2+b][c*2+d])

main()
0