結果

問題 No.2376 障害物競プロ
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-07-03 12:51:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,757 ms / 4,000 ms
コード長 1,800 bytes
コンパイル時間 2,044 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 81,796 KB
最終ジャッジ日時 2023-09-24 09:54:22
合計ジャッジ時間 90,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,384 KB
testcase_01 AC 71 ms
71,556 KB
testcase_02 AC 78 ms
71,584 KB
testcase_03 AC 74 ms
71,504 KB
testcase_04 AC 623 ms
79,288 KB
testcase_05 AC 847 ms
79,164 KB
testcase_06 AC 540 ms
79,592 KB
testcase_07 AC 1,723 ms
80,324 KB
testcase_08 AC 1,660 ms
80,368 KB
testcase_09 AC 1,757 ms
81,208 KB
testcase_10 AC 1,754 ms
81,084 KB
testcase_11 AC 1,742 ms
81,116 KB
testcase_12 AC 1,698 ms
81,776 KB
testcase_13 AC 1,548 ms
80,400 KB
testcase_14 AC 1,723 ms
81,268 KB
testcase_15 AC 1,571 ms
80,284 KB
testcase_16 AC 1,720 ms
80,776 KB
testcase_17 AC 1,727 ms
81,044 KB
testcase_18 AC 1,728 ms
81,796 KB
testcase_19 AC 1,521 ms
80,088 KB
testcase_20 AC 1,572 ms
80,116 KB
testcase_21 AC 1,580 ms
80,576 KB
testcase_22 AC 1,176 ms
79,908 KB
testcase_23 AC 1,107 ms
79,736 KB
testcase_24 AC 584 ms
78,564 KB
testcase_25 AC 401 ms
78,824 KB
testcase_26 AC 647 ms
78,744 KB
testcase_27 AC 628 ms
79,296 KB
testcase_28 AC 658 ms
80,000 KB
testcase_29 AC 415 ms
79,092 KB
testcase_30 AC 991 ms
80,200 KB
testcase_31 AC 587 ms
79,916 KB
testcase_32 AC 245 ms
79,320 KB
testcase_33 AC 470 ms
80,252 KB
testcase_34 AC 445 ms
80,060 KB
testcase_35 AC 235 ms
78,680 KB
testcase_36 AC 1,335 ms
80,260 KB
testcase_37 AC 948 ms
80,444 KB
testcase_38 AC 472 ms
79,304 KB
testcase_39 AC 1,469 ms
80,324 KB
testcase_40 AC 1,003 ms
80,024 KB
testcase_41 AC 425 ms
79,364 KB
testcase_42 AC 1,714 ms
80,380 KB
testcase_43 AC 1,704 ms
80,500 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:
            if ((q1-p1).conjugate()*(q2-p1)).real <= 0:
                return True
            if ((q1-p2).conjugate()*(q2-p2)).real <= 0:
                return True
            if ((p1-q1).conjugate()*(p2-q1)).real <= 0:
                return True
            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