結果

問題 No.2180 Comprehensive Line Segments
ユーザー ShirotsumeShirotsume
提出日時 2022-12-30 22:19:45
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,227 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 88,396 KB
最終ジャッジ日時 2023-08-21 05:57:24
合計ジャッジ時間 31,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
78,348 KB
testcase_01 AC 96 ms
71,792 KB
testcase_02 AC 93 ms
71,792 KB
testcase_03 AC 2,762 ms
88,128 KB
testcase_04 AC 93 ms
71,712 KB
testcase_05 AC 93 ms
71,852 KB
testcase_06 AC 93 ms
71,788 KB
testcase_07 AC 94 ms
71,808 KB
testcase_08 AC 93 ms
71,856 KB
testcase_09 AC 2,107 ms
87,496 KB
testcase_10 AC 2,361 ms
87,912 KB
testcase_11 AC 2,604 ms
87,684 KB
testcase_12 AC 1,036 ms
82,520 KB
testcase_13 AC 2,589 ms
88,396 KB
testcase_14 AC 2,574 ms
87,376 KB
testcase_15 AC 2,729 ms
87,996 KB
testcase_16 AC 234 ms
79,568 KB
testcase_17 AC 447 ms
80,192 KB
testcase_18 AC 2,781 ms
88,384 KB
testcase_19 AC 999 ms
82,428 KB
testcase_20 AC 108 ms
77,380 KB
testcase_21 AC 465 ms
80,220 KB
testcase_22 AC 126 ms
78,288 KB
testcase_23 AC 173 ms
79,064 KB
testcase_24 AC 142 ms
78,548 KB
testcase_25 AC 244 ms
79,636 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 441 ms
80,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
sys.setrecursionlimit(5 * 10 ** 5)
from pypyjit import set_param
set_param('max_unroll_recursion=-1')
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
import itertools
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):
		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: int) -> int:
	if(x > 0):
		return 1
	if(x < 0):
		return -1
	return 0

def same_inclination(v1: Vector2, v2: Vector2) -> bool:
	return (v1 * v2 == 0 and (v1.x * v2.x > 0 or v1.y * v2.y > 0))


n = ii()

XY = [Vector2(*li()) for _ in range(n)]


dp = [[[n] * n for _ in range(n)] for _ in range(1<<n)]

vlis = [[None] * n for _ in range(n)]
P = list(itertools.permutations(range(n), 2))
for v in P:
	vlis[v[0]][v[1]] = XY[v[1]] - XY[v[0]]
	dp[(1<<v[0]) | (1<<v[1])][v[0]][v[1]] = 1


for bit in range(3, 1<<n):
	for vfr, vnow in P:
		if dp[bit][vfr][vnow] == n or not(1 & (bit >> vfr)) or not(1 & (bit >> vnow)):
			continue
		cnext = cnow = dp[bit][vfr][vnow]
		v1 = vlis[vfr][vnow]
		for tox, toy in P:
			if (1 & (bit >> tox) and vnow != tox) or 1 & (bit >> toy) : continue
			bitto = bit | (1<<tox) | (1 << toy)
			v2 = vlis[vnow][tox]
			v3 = vlis[tox][toy]
			if(vnow == tox):
				cnext = cnow + 1 - same_inclination(v1, v3)
			else:
				d = same_inclination(v1, v2) + same_inclination(v2, v3)
				if(d == 0):
					d = (sgn(v1 * v2) == sgn(v2 * v3) == sgn(v1 * v3))
				cnext = cnow + 2 - d
			dp[bitto][tox][toy] = min(dp[bitto][tox][toy], cnext)

print(min(min(v) for v in dp[(1<<n)-1]))


0