結果
問題 | No.2180 Comprehensive Line Segments |
ユーザー |
![]() |
提出日時 | 2022-10-13 11:53:54 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,409 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 82,504 KB |
実行使用メモリ | 196,220 KB |
最終ジャッジ日時 | 2024-11-17 01:22:40 |
合計ジャッジ時間 | 109,054 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 TLE * 1 |
other | AC * 9 TLE * 16 |
ソースコード
import sysfrom itertools import permutationsfrom fractions import Fraction as fracinput = sys.stdin.readlineclass Vector2:def __init__(self, x: frac, y: frac):self.x = xself.y = ydef __eq__(self, other):return (self.x == other.x and self.y == other.y)def __sub__(self, other):return Vector2(other.x - self.x, other.y - self.y)def __mul__(self, other):return self.x * other.y - self.y * other.xdef normalize_vector(v: Vector2) -> Vector2:assert(v.x != 0 or v.y != 0)norm = v.x ** 2 + v.y ** 2return Vector2(v.x * abs(v.x) / norm, v.y * abs(v.y) / norm)def sgn(x: frac) -> int:if(x > 0):return 1if(x < 0):return -1return 0"""Main Code"""N = int(input())P = [Vector2(*map(frac, input().split())) for _ in [0] * N]if(N == 1):print(1)exit(0)ans = Nfor p in permutations(P):lis = [normalize_vector(p[1] - p[0])]flag = Falsefor i in range(1, N - 1):v = normalize_vector(p[i + 1] - p[i])if(lis[-1] == v):continueif(lis[-1] * v == 0):flag = Truebreaklis.append(v)if(flag):continueM = len(lis)if(M <= 2):ans = min(ans, M)continuedp = [[-1]*2 for _ in [0]*(M - 1)]dp[0][0] = 0for j in range(1, M - 1):v1, v2, v3 = lis[j - 1: j + 2]if(sgn(v1 * v2) == sgn(v2 * v3) == sgn(v1 * v3)):dp[j][1] = dp[j - 1][0] + 1dp[j][0] = max(dp[j - 1])ans = min(ans, M - max(dp[M - 2]))print(ans)