結果

問題 No.2180 Comprehensive Line Segments
ユーザー MasKoaTSMasKoaTS
提出日時 2022-10-11 21:04:43
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,624 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 189,544 KB
最終ジャッジ日時 2024-04-28 10:32:58
合計ジャッジ時間 7,638 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 401 ms
189,544 KB
testcase_01 AC 131 ms
88,576 KB
testcase_02 AC 126 ms
88,428 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from fractions import Fraction as frac
input = sys.stdin.readline


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

	def __sub__(self, other):
		return Vector2(other.x - self.x, other.y - self.y)

def be_same_inclination(one: Vector2, other: Vector2) -> bool:
	if(one.x == 0):
		return (other.x == 0 and one.y / other.y > 0)
	a = other.x / one.x
	return (a * one.y == other.y and a > 0)

def calc_outer_product(one: Vector2, other: Vector2) -> frac:
	return one.x * other.y - one.y * other.x


def sgn(x: frac) -> int:
	if(x > 0):
		return 1
	if(x < 0):
		return -1
	return 0

def is_continuous_bit(bit: int) -> bool:
	while(bit):
		if((bit & 3) == 3):
			return True
		bit >>= 1
	return False


"""
Main Code
"""

N = int(input())
P = [Vector2(*map(frac, input().split())) for _ in [0] * N]

if(N == 1):
	print(1)
	exit(0)

ans = N
for p in permutations(P):
	lis = [p[1] - p[0]]
	flag = False
	for i in range(1, N - 1):
		v = p[i + 1] - p[i]
		if(be_same_inclination(lis[-1], v)):
			continue
		if(calc_outer_product(lis[-1], v) == 0):
			flag = True
			break
		lis.append(v)
	if(flag):
		continue

	M = len(lis)
	if(M <= 2):
		ans = min(ans, M)
		continue

	for i in range(1 << (M - 2)):
		if(is_continuous_bit(i)):
			continue
		bit = i << 1
		cnt = M
		for j in range(1, N - 1):
			if(((bit >> j) & 1) == 0):
				continue
			v1, v2, v3 = lis[j-1:j+2]
			op1, op2, op3 = calc_outer_product(v1, v2), calc_outer_product(v2, v3), calc_outer_product(v1, v3)
			if(sgn(op1) == sgn(op2) == sgn(op3)):
				cnt -= 1
		ans = min(ans, cnt)

print(ans)
0