結果
問題 | No.2376 障害物競プロ |
ユーザー | ks2m |
提出日時 | 2023-07-07 23:05:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,027 ms / 4,000 ms |
コード長 | 3,079 bytes |
コンパイル時間 | 4,973 ms |
コンパイル使用メモリ | 73,392 KB |
実行使用メモリ | 50,788 KB |
最終ジャッジ日時 | 2023-09-29 00:50:29 |
合計ジャッジ時間 | 74,472 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
33,784 KB |
testcase_01 | AC | 40 ms
33,524 KB |
testcase_02 | AC | 39 ms
33,900 KB |
testcase_03 | AC | 38 ms
33,548 KB |
testcase_04 | AC | 574 ms
45,856 KB |
testcase_05 | AC | 665 ms
47,076 KB |
testcase_06 | AC | 495 ms
44,400 KB |
testcase_07 | AC | 813 ms
46,840 KB |
testcase_08 | AC | 809 ms
47,120 KB |
testcase_09 | AC | 795 ms
46,888 KB |
testcase_10 | AC | 808 ms
46,876 KB |
testcase_11 | AC | 868 ms
48,984 KB |
testcase_12 | AC | 796 ms
48,284 KB |
testcase_13 | AC | 806 ms
47,600 KB |
testcase_14 | AC | 792 ms
48,724 KB |
testcase_15 | AC | 759 ms
48,096 KB |
testcase_16 | AC | 711 ms
47,552 KB |
testcase_17 | AC | 798 ms
47,964 KB |
testcase_18 | AC | 787 ms
49,948 KB |
testcase_19 | AC | 915 ms
46,948 KB |
testcase_20 | AC | 1,027 ms
50,788 KB |
testcase_21 | AC | 897 ms
48,980 KB |
testcase_22 | AC | 711 ms
47,072 KB |
testcase_23 | AC | 642 ms
45,392 KB |
testcase_24 | AC | 560 ms
46,516 KB |
testcase_25 | AC | 430 ms
43,792 KB |
testcase_26 | AC | 606 ms
46,648 KB |
testcase_27 | AC | 582 ms
45,492 KB |
testcase_28 | AC | 501 ms
43,956 KB |
testcase_29 | AC | 437 ms
44,128 KB |
testcase_30 | AC | 484 ms
44,048 KB |
testcase_31 | AC | 503 ms
44,508 KB |
testcase_32 | AC | 207 ms
40,508 KB |
testcase_33 | AC | 297 ms
42,960 KB |
testcase_34 | AC | 350 ms
43,280 KB |
testcase_35 | AC | 267 ms
42,804 KB |
testcase_36 | AC | 663 ms
45,428 KB |
testcase_37 | AC | 723 ms
46,712 KB |
testcase_38 | AC | 437 ms
44,140 KB |
testcase_39 | AC | 782 ms
46,948 KB |
testcase_40 | AC | 428 ms
43,520 KB |
testcase_41 | AC | 424 ms
44,236 KB |
testcase_42 | AC | 883 ms
48,876 KB |
testcase_43 | AC | 884 ms
47,880 KB |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); int n2 = n * 2; Point[] arr = new Point[n2]; for (int i = 0; i < n; i++) { sa = br.readLine().split(" "); Point p1 = new Point(); p1.x = Integer.parseInt(sa[0]); p1.y = Integer.parseInt(sa[1]); Point p2 = new Point(); p2.x = Integer.parseInt(sa[2]); p2.y = Integer.parseInt(sa[3]); arr[i] = p1; arr[i + n] = p2; } int[] a = new int[m]; int[] b = new int[m]; int[] c = new int[m]; int[] d = new int[m]; for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); a[i] = Integer.parseInt(sa[0]) - 1; b[i] = Integer.parseInt(sa[1]); c[i] = Integer.parseInt(sa[2]) - 1; d[i] = Integer.parseInt(sa[3]); } br.close(); double inf = 1e18; double[][] dist = new double[n2][n2]; for (int i = 0; i < n2; i++) { for (int j = i + 1; j < n2; j++) { boolean flg = true; for (int k = 0; k < n; k++) { if (i % n != k && j % n != k) { if (cross(arr[i], arr[j], arr[k], arr[k + n])) { flg = false; break; } } } if (flg) { dist[i][j] = Math.hypot(arr[i].x - arr[j].x, arr[i].y - arr[j].y); } else { dist[i][j] = inf; } dist[j][i] = dist[i][j]; } } for (int k = 0; k < n2; k++) { for (int i = 0; i < n2; i++) { for (int j = 0; j < n2; j++) { if (dist[i][k] != inf && dist[k][j] != inf) { dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]); } } } } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < m; i++) { int p1 = a[i]; if (b[i] == 2) { p1 += n; } int p2 = c[i]; if (d[i] == 2) { p2 += n; } pw.println(dist[p1][p2]); } pw.flush(); } static boolean cross(Point a, Point b, Point c, Point d) { // AB-C long s1 = (long) (a.x - b.x) * (c.y - a.y) - (long) (a.y - b.y) * (c.x - a.x); // AB-D long t1 = (long) (a.x - b.x) * (d.y - a.y) - (long) (a.y - b.y) * (d.x - a.x); if (s1 > 0 && t1 > 0 || s1 < 0 && t1 < 0) { return false; } // CD-A long s2 = (long) (c.x - d.x) * (a.y - c.y) - (long) (c.y - d.y) * (a.x - c.x); // CD-B long t2 = (long) (c.x - d.x) * (b.y - c.y) - (long) (c.y - d.y) * (b.x - c.x); if (s2 > 0 && t2 > 0 || s2 < 0 && t2 < 0) { return false; } if (s1 == 0 && t1 == 0 && s2 == 0 && t2 == 0) { int ax = Math.min(a.x, b.x); int bx = Math.max(a.x, b.x); int ay = Math.min(a.y, b.y); int by = Math.max(a.y, b.y); int cx = Math.min(c.x, d.x); int dx = Math.max(c.x, d.x); int cy = Math.min(c.y, d.y); int dy = Math.max(c.y, d.y); // D < A || B < C if (dx < ax || dy < ay || bx < cx || by < cy) { return false; } return true; } else { return true; } } static class Point { int x, y; } }