結果
問題 | No.2602 Real Collider |
ユーザー | Maksym Shcherban |
提出日時 | 2024-01-12 23:37:40 |
言語 | JavaScript (node v21.7.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,284 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 5,632 KB |
実行使用メモリ | 69,872 KB |
最終ジャッジ日時 | 2024-09-28 00:22:45 |
合計ジャッジ時間 | 64,713 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
39,168 KB |
testcase_01 | AC | 66 ms
39,296 KB |
testcase_02 | AC | 68 ms
39,040 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 67 ms
38,912 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 824 ms
58,064 KB |
testcase_12 | AC | 919 ms
59,768 KB |
testcase_13 | AC | 658 ms
56,360 KB |
testcase_14 | AC | 971 ms
60,052 KB |
testcase_15 | AC | 708 ms
57,100 KB |
testcase_16 | AC | 886 ms
60,404 KB |
testcase_17 | AC | 959 ms
59,884 KB |
testcase_18 | AC | 776 ms
57,864 KB |
testcase_19 | AC | 851 ms
59,940 KB |
testcase_20 | AC | 1,006 ms
60,588 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 815 ms
58,472 KB |
testcase_25 | AC | 833 ms
59,988 KB |
testcase_26 | AC | 713 ms
57,124 KB |
testcase_27 | AC | 895 ms
60,332 KB |
testcase_28 | AC | 928 ms
60,572 KB |
testcase_29 | WA | - |
testcase_30 | AC | 877 ms
60,200 KB |
testcase_31 | AC | 893 ms
60,404 KB |
testcase_32 | AC | 809 ms
58,300 KB |
testcase_33 | AC | 886 ms
60,320 KB |
testcase_34 | AC | 903 ms
60,276 KB |
testcase_35 | AC | 704 ms
57,004 KB |
testcase_36 | AC | 712 ms
57,004 KB |
testcase_37 | AC | 924 ms
59,476 KB |
testcase_38 | AC | 941 ms
59,792 KB |
testcase_39 | AC | 943 ms
59,472 KB |
testcase_40 | AC | 675 ms
56,444 KB |
testcase_41 | AC | 976 ms
60,500 KB |
testcase_42 | AC | 879 ms
60,052 KB |
testcase_43 | AC | 888 ms
60,356 KB |
testcase_44 | AC | 1,009 ms
60,360 KB |
testcase_45 | AC | 785 ms
57,848 KB |
testcase_46 | AC | 753 ms
57,424 KB |
testcase_47 | AC | 954 ms
59,772 KB |
testcase_48 | AC | 799 ms
58,372 KB |
testcase_49 | AC | 756 ms
57,220 KB |
testcase_50 | AC | 689 ms
56,240 KB |
testcase_51 | AC | 692 ms
56,588 KB |
testcase_52 | AC | 604 ms
51,804 KB |
testcase_53 | AC | 905 ms
60,500 KB |
testcase_54 | AC | 787 ms
57,752 KB |
testcase_55 | AC | 829 ms
58,264 KB |
testcase_56 | AC | 806 ms
58,224 KB |
testcase_57 | AC | 797 ms
58,104 KB |
testcase_58 | AC | 497 ms
51,492 KB |
testcase_59 | AC | 877 ms
60,392 KB |
testcase_60 | AC | 820 ms
58,452 KB |
testcase_61 | AC | 739 ms
57,260 KB |
testcase_62 | AC | 902 ms
60,516 KB |
testcase_63 | AC | 967 ms
60,032 KB |
testcase_64 | AC | 1,039 ms
60,928 KB |
testcase_65 | AC | 744 ms
57,260 KB |
testcase_66 | AC | 923 ms
59,864 KB |
testcase_67 | AC | 663 ms
56,164 KB |
testcase_68 | AC | 698 ms
56,728 KB |
testcase_69 | AC | 603 ms
51,912 KB |
testcase_70 | AC | 647 ms
56,288 KB |
testcase_71 | AC | 711 ms
57,128 KB |
testcase_72 | AC | 875 ms
60,100 KB |
testcase_73 | AC | 808 ms
57,976 KB |
testcase_74 | AC | 870 ms
60,476 KB |
testcase_75 | AC | 936 ms
59,600 KB |
testcase_76 | AC | 862 ms
60,164 KB |
testcase_77 | AC | 887 ms
60,360 KB |
testcase_78 | AC | 974 ms
60,496 KB |
testcase_79 | AC | 933 ms
60,692 KB |
testcase_80 | AC | 990 ms
60,232 KB |
ソースコード
class Point { constructor(x, y) { this.x = x; this.y = y; } } class Circle { constructor(x, y, r) { this.x = x; this.y = y; this.r = r; } } /* * Returns the smallest circle that encloses all the given points. Runs in expected O(n) time, randomized. * Note: If 0 points are given, null is returned. If 1 point is given, a circle of radius 0 is returned. */ // Initially: No boundary points known function makeCircle(points) { // Clone list to preserve the caller's data, do Durstenfeld shuffle let shuffled = points.slice(); for (let i = points.length - 1; i >= 0; i--) { let j = Math.floor(Math.random() * (i + 1)); j = Math.max(Math.min(j, i), 0); const temp = shuffled[i]; shuffled[i] = shuffled[j]; shuffled[j] = temp; } // Progressively add points to circle or recompute circle let c = null; shuffled.forEach((p, i) => { if (c === null || !isInCircle(c, p)) c = makeCircleOnePoint(shuffled.slice(0, i + 1), p); }); return c; } // One boundary point known function makeCircleOnePoint(points, p) { let c = new Circle(p.x, p.y, 0); points.forEach((q, i) => { if (!isInCircle(c, q)) { if (c.r == 0) c = makeDiameter(p, q); else c = makeCircleTwoPoints(points.slice(0, i + 1), p, q); } }); return c; } // Two boundary points known function makeCircleTwoPoints(points, p, q) { const circ = makeDiameter(p, q); let left = null; let right = null; // For each point not in the two-point circle for (const r of points) { if (isInCircle(circ, r)) continue; // Form a circumcircle and classify it on left or right side const cross = crossProduct(p.x, p.y, q.x, q.y, r.x, r.y); const c = makeCircumcircle(p, q, r); if (c === null) continue; else if (cross > 0 && (left === null || crossProduct(p.x, p.y, q.x, q.y, c.x, c.y) > crossProduct(p.x, p.y, q.x, q.y, left.x, left.y))) left = c; else if (cross < 0 && (right === null || crossProduct(p.x, p.y, q.x, q.y, c.x, c.y) < crossProduct(p.x, p.y, q.x, q.y, right.x, right.y))) right = c; } // Select which circle to return if (left === null && right === null) return circ; else if (left === null && right !== null) return right; else if (left !== null && right === null) return left; else if (left !== null && right !== null) return left.r <= right.r ? left : right; else throw new Error("Assertion error"); } function makeDiameter(a, b) { const cx = (a.x + b.x) / 2; const cy = (a.y + b.y) / 2; const r0 = distance(cx, cy, a.x, a.y); const r1 = distance(cx, cy, b.x, b.y); return new Circle(cx, cy, Math.max(r0, r1)); } function makeCircumcircle(a, b, c) { // Mathematical algorithm from Wikipedia: Circumscribed circle const ox = (Math.min(a.x, b.x, c.x) + Math.max(a.x, b.x, c.x)) / 2; const oy = (Math.min(a.y, b.y, c.y) + Math.max(a.y, b.y, c.y)) / 2; const ax = a.x - ox; const ay = a.y - oy; const bx = b.x - ox; const by = b.y - oy; const cx = c.x - ox; const cy = c.y - oy; const d = (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) * 2; if (d == 0) return null; const x = ox + ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by) * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / d; const y = oy + ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by) * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / d; const ra = distance(x, y, a.x, a.y); const rb = distance(x, y, b.x, b.y); const rc = distance(x, y, c.x, c.y); return new Circle(x, y, Math.max(ra, rb, rc)); } /* Simple mathematical functions */ const MULTIPLICATIVE_EPSILON = 1 + 1e-14; function isInCircle(c, p) { return c !== null && distance(p.x, p.y, c.x, c.y) <= c.r * MULTIPLICATIVE_EPSILON; } // Returns twice the signed area of the triangle defined by (x0, y0), (x1, y1), (x2, y2). function crossProduct(x0, y0, x1, y1, x2, y2) { return (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0); } function distance(x0, y0, x1, y1) { return Math.hypot(x0 - x1, y0 - y1); } function makeCircleSimple(a, b, c) { const r = Math.hypot(a.x - b.x, a.y - b.y) / 2; const x = (a.x + b.x) / 2; const y = (a.y + b.y) / 2; const cd = Math.hypot(c.x - x, c.y - y); if (cd < r) { return {r, x, y}; } return null; } function Main(input) { const lines = input.split('\n').map(x => x.trim()).filter(Boolean); const q = +lines[0]; const [xa, ya, xb, yb, xc, yc] = lines[1].split(' ').map(Number); const pa = new Point(xa, ya); const pb = new Point(xb, yb); const pc = new Point(xc, yc); const circle = makeCircleSimple(pa, pb, pc) || makeCircleSimple(pa, pc, pb) || makeCircleSimple(pc, pb, pa) || makeCircle([pa, pb, pc]); for (let i = 0; i < q; i++) { const [x, y] = lines[2 + i].split(' ').map(Number); const d = Math.hypot(x - circle.x, y - circle.y); const result = d <= circle.r ? 'Yes' : 'No'; console.log(result); } } Main(require("fs").readFileSync("/dev/stdin", "utf8"));