結果
問題 | No.2180 Comprehensive Line Segments |
ユーザー | MasKoaTS |
提出日時 | 2022-09-10 13:31:15 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,825 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 887,696 KB |
最終ジャッジ日時 | 2024-11-17 00:45:04 |
合計ジャッジ時間 | 93,386 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 346 ms
100,352 KB |
testcase_01 | AC | 168 ms
224,188 KB |
testcase_02 | MLE | - |
testcase_03 | TLE | - |
testcase_04 | MLE | - |
testcase_05 | AC | 138 ms
88,436 KB |
testcase_06 | AC | 139 ms
88,624 KB |
testcase_07 | MLE | - |
testcase_08 | AC | 160 ms
89,016 KB |
testcase_09 | AC | 326 ms
142,716 KB |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | AC | 324 ms
90,948 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 535 ms
102,396 KB |
testcase_23 | AC | 2,942 ms
345,208 KB |
testcase_24 | AC | 1,289 ms
160,392 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | WA | - |
testcase_28 | MLE | - |
ソースコード
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) """ Main Code """ N = int(input()) P = [Point(*map(frac, input().split())) for _ in [0] * N] if(N == 1): print(1) exit(0) ph = {} pt_id = 0 for p in P: ph[p] = pt_id pt_id += 1 ln_id = 0 lh = {} for i in range(N - 1): for j in range(1, N): p1, p2 = P[i], P[j] l = p1.calcLine(p2) if(l in lh): continue lh[l] = ln_id ln_id += 1 lis = list(lh.keys()) for i in range(ln_id - 1): for j in range(1, ln_id): l1, l2 = lis[i], lis[j] p = l1.intersection(l2) if(p is None or p in ph): continue P.append(p) ph[p] = pt_id pt_id += 1 dir_lis = [[None]*pt_id for _ in [0]*pt_id] for i in range(pt_id - 1): for j in range(1, pt_id): p1, p2 = P[i], P[j] l = p1.calcLine(p2) if(l not in lh): continue dir_lis[i][j] = (lh[l], (p1 < p2)) dir_lis[j][i] = (lh[l], (p2 < p1)) dp = [[[[INF]*2 for _ in [0]*(ln_id + 1)] for _ in [0]*pt_id] for _ in [0]*(1 << N)] que = deque([]) for i in range(N): que.append((0, 1 << i, i, ln_id, 0)) dp[1 << i][i][ln_id][0] = 0 goal = (1 << N) - 1 ans = INF cnt = 0 while(que): c, b, v, l, a = que.popleft() if(c > dp[b][v][l][a]): continue if(b == goal): ans = c break for nv in range(pt_id): nb = b if(nv < N): nb = b | (1 << nv) if(dir_lis[v][nv] is None): continue nl, na = dir_lis[v][nv] nc = c if(l is None or (l, a) != (nl, na)): nc += 1 if(nc >= dp[nb][nv][nl][na]): continue dp[nb][nv][nl][na] = nc if(nc == c): que.appendleft((nc, nb, nv, nl, na)) else: que.append((nc, nb, nv, nl, na)) print(ans)