結果

問題 No.2180 Comprehensive Line Segments
ユーザー ShirotsumeShirotsume
提出日時 2022-10-07 17:03:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,388 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 351,260 KB
最終ジャッジ日時 2024-11-17 00:59:11
合計ジャッジ時間 48,087 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 TLE -
testcase_04 AC 147 ms
88,948 KB
testcase_05 AC 138 ms
88,528 KB
testcase_06 AC 142 ms
88,372 KB
testcase_07 AC 149 ms
88,568 KB
testcase_08 WA -
testcase_09 AC 417 ms
119,604 KB
testcase_10 AC 856 ms
137,320 KB
testcase_11 AC 780 ms
124,144 KB
testcase_12 WA -
testcase_13 TLE -
testcase_14 WA -
testcase_15 TLE -
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 763 ms
351,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2**63-1
mod = 998244353
import sys
from collections import deque
from fractions import Fraction as frac
input = sys.stdin.readline
INF = 10 ** 9

class Point:
	def __init__(self, x: frac, y: frac):
		self.x = x
		self.y = y

	def __eq__(self, other):
		return (self.x == other.x and self.y == other.y)

	def __hash__(self):
		return hash((self.x, self.y))

	def __lt__(self, other):
		if(self.x == other.x):
			return (self.y < other.y)
		return (self.x < other.x)

	def show(self):
		print(self.x, self.y)

	def calcLine(self, other):
		x1 = self.x;  y1 = self.y
		x2 = other.x;  y2 = other.y
		if(x1 == x2):
			return Line(frac(1), frac(0), x1)
		a = (y1 - y2) / (x1 - x2)
		c = y1 - a * x1
		return Line(-a, frac(1), c)
class Line:
	def __init__(self, a: frac, b:frac, c:frac):
		self.a = a
		self.b = b
		self.c = c

	def __eq__(self, other):
		return (self.a == other.a and self.b == other.b and self.c == other.c)

	def __hash__(self):
		return hash((self.a, self.b, self.c))

	def show(self):
		print((self.a, self.b, self.c))

	def intersection(self, other) -> Point:
		p = self.a * other.b - other.a * self.b
		if(p == frac(0)):
			return None
		q = other.b * self.c - self.b * other.c
		x = q / p
		y = (other.c - other.a * x) / other.b if(self.b == 0) else (self.c - self.a * x) / self.b
		return Point(x, y)
n = ii()

XY = [li() for _ in range(n)]

dp = [[defaultdict(lambda:inf) for _ in range(n)] for _ in range(2**n)]
q = deque()
for i in range(n):
    dp[2**i][i][(Line(-inf, -inf, -inf), 0)] = 0
    q.append((2**i,i,(Line(-inf, -inf, -inf), 0)))

while q:
    bit, now, l = q.popleft()
    if bit == ((2**n) - 1):
        print(dp[bit][now][l])
        break
    for to in range(n):
        if now == to:
            continue
        l2 = (Point(*XY[now]).calcLine(Point(*XY[to])), XY[now] < XY[to])
        if l == l2:
            if dp[bit ^ (2**to)][to][l] > dp[bit][now][l]:
                dp[bit^(2**to)][to][l] = dp[bit][now][l]
                q.appendleft((bit^(2**to), to, l))
        else:
            if dp[bit ^ (2**to)][to][l2] > dp[bit][now][l] + 1:
                dp[bit^(2**to)][to][l2] = dp[bit][now][l] + 1
                q.append((bit^(2**to), to, l2))
0