結果
問題 | No.2180 Comprehensive Line Segments |
ユーザー | MasKoaTS |
提出日時 | 2022-11-30 22:01:59 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,866 bytes |
コンパイル時間 | 345 ms |
コンパイル使用メモリ | 81,908 KB |
実行使用メモリ | 187,520 KB |
最終ジャッジ日時 | 2024-11-17 01:34:34 |
合計ジャッジ時間 | 109,336 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 367 ms
98,300 KB |
testcase_01 | AC | 142 ms
181,752 KB |
testcase_02 | AC | 139 ms
180,844 KB |
testcase_03 | TLE | - |
testcase_04 | AC | 142 ms
95,104 KB |
testcase_05 | AC | 144 ms
186,636 KB |
testcase_06 | AC | 142 ms
187,520 KB |
testcase_07 | AC | 137 ms
95,120 KB |
testcase_08 | AC | 143 ms
93,696 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
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 | 166 ms
89,216 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 400 ms
91,380 KB |
testcase_23 | AC | 2,397 ms
107,624 KB |
testcase_24 | AC | 1,012 ms
97,556 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
ソースコード
from __future__ import annotations import sys from itertools import permutations from fractions import Fraction as frac input = sys.stdin.readline class Vector2: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return str((self.x, self.y)) __repr__ = __str__ def __eq__(self, other): return (self.x == other.x and self.y == other.y) def __hash__(self): return hash((self.x, self.y)) def __add__(self, other): return Vector2(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector2(self.x - other.x, self.y - other.y) def __mul__(self, other): return self.x * other.y - self.y * other.x def normalize(self) -> Vector2: assert(self.x != 0 or self.y != 0) norm = self.x ** 2 + self.y ** 2 self.x *= abs(self.x) / norm self.y *= abs(self.y) / norm return self def sgn(x: frac) -> int: if(x > 0): return 1 if(x < 0): return -1 return 0 """ Main Code """ N = int(input()) P = [Vector2(*map(frac, input().split())) for _ in [0] * N] if(N == 1): print(1) exit(0) vec_lis = [[None]*N for _ in [0]*N] for i in range(N - 1): for j in range(i + 1, N): vec_lis[i][j] = (P[j] - P[i]).normalize() vec_lis[j][i] = (P[i] - P[j]).normalize() ans = N num = [*range(N)] for tup in permutations(num): p = [P[k] for k in num] lis = [vec_lis[tup[0]][tup[1]]] flag = False for i in range(1, N - 1): v = vec_lis[tup[i]][tup[i + 1]] if(lis[-1] == v): continue if(lis[-1] * v == 0): flag = True break lis.append(v) if(flag): continue M = len(lis) if(M <= 2): ans = min(ans, M) continue dp = [[-1]*2 for _ in [0]*(M - 1)] dp[0][0] = 0 for 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] + 1 dp[j][0] = max(dp[j - 1]) ans = min(ans, M - max(dp[M - 2])) print(ans)