結果
問題 | No.2180 Comprehensive Line Segments |
ユーザー | MasKoaTS |
提出日時 | 2022-12-17 13:46:45 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,336 bytes |
コンパイル時間 | 508 ms |
コンパイル使用メモリ | 82,016 KB |
実行使用メモリ | 216,092 KB |
最終ジャッジ日時 | 2024-11-17 01:38:32 |
合計ジャッジ時間 | 77,713 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 335 ms
97,840 KB |
testcase_01 | AC | 143 ms
193,900 KB |
testcase_02 | AC | 139 ms
191,292 KB |
testcase_03 | TLE | - |
testcase_04 | AC | 144 ms
95,404 KB |
testcase_05 | AC | 141 ms
197,664 KB |
testcase_06 | AC | 140 ms
95,404 KB |
testcase_07 | AC | 143 ms
88,468 KB |
testcase_08 | AC | 145 ms
88,500 KB |
testcase_09 | AC | 3,947 ms
102,584 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 3,194 ms
100,332 KB |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | AC | 1,584 ms
100,472 KB |
testcase_17 | AC | 2,430 ms
101,000 KB |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | AC | 172 ms
89,196 KB |
testcase_21 | AC | 2,439 ms
101,400 KB |
testcase_22 | AC | 307 ms
90,620 KB |
testcase_23 | AC | 926 ms
95,680 KB |
testcase_24 | AC | 573 ms
92,364 KB |
testcase_25 | AC | 1,486 ms
99,152 KB |
testcase_26 | TLE | - |
testcase_27 | WA | - |
testcase_28 | AC | 2,189 ms
216,092 KB |
ソースコード
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 dp = [[[N]*N for _ in [0]*N] for _ in [0]*(1 << N)] num = [*range(N)] for i, j in permutations(num, 2): dp[(1 << i) | (1 << j)][i][j] = 1 goal = (1 << N) - 1 for b_now in range(3, goal): for v_prev, v_now in permutations(num, 2): if(dp[b_now][v_prev][v_now] == N or not((b_now >> v_prev) & 1) or not((b_now >> v_now) & 1)): continue c_next = c_now = dp[b_now][v_prev][v_now] v1 = vec_lis[v_prev][v_now] for v_next1, v_next2 in permutations(num, 2): if((((b_now >> v_next1) & 1) and v_now != v_next1) or ((b_now >> v_next2) & 1)): continue b_next = b_now | (1 << v_next1) | (1 << v_next2) v2, v3 = vec_lis[v_now][v_next1], vec_lis[v_next1][v_next2] if(v_now == v_next1): c_next = c_now + (v1 != v3) else: d = (v1 == v2) + (v2 == v3) if(d == 0): d = (sgn(v1 * v2) == sgn(v2 * v3) == sgn(v1 * v3)) c_next = c_now + 2 - d # print(b_now, b_next, v_prev, v_now, v_next1, v_next2, c_now, c_next) if(dp[b_next][v_next1][v_next2] <= c_next): continue dp[b_next][v_next1][v_next2] = c_next ans = min(min(lis) for lis in dp[goal]) print(ans)