結果
| 問題 |
No.2180 Comprehensive Line Segments
|
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2025-07-09 00:56:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,395 bytes |
| コンパイル時間 | 328 ms |
| コンパイル使用メモリ | 81,860 KB |
| 実行使用メモリ | 77,704 KB |
| 最終ジャッジ日時 | 2025-07-09 00:57:06 |
| 合計ジャッジ時間 | 5,455 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 5 |
ソースコード
import sys
from itertools import combinations
from functools import lru_cache
# 三点が同一直線上にあるかを判定
def is_colinear(p1, p2, p3):
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
return (x2 - x1) * (y3 - y1) == (x3 - x1) * (y2 - y1)
# 与えられた点集合が全て一直線上にあるか判定
def is_all_colinear(points):
if len(points) <= 2:
return True
p1, p2 = points[0], points[1]
for i in range(2, len(points)):
if not is_colinear(p1, p2, points[i]):
return False
return True
def main():
input = sys.stdin.read
data = input().strip().split('\n')
N = int(data[0])
points = [tuple(map(int, line.split())) for line in data[1:]]
# すべての一直線上の部分集合を列挙(ビットマスクで管理)
line_sets = []
for mask in range(1, 1 << N):
subset = [points[i] for i in range(N) if (mask >> i) & 1]
if is_all_colinear(subset):
line_sets.append(mask)
# メモ化再帰で最小の線分数を探索
@lru_cache(None)
def dfs(used_mask):
if used_mask == (1 << N) - 1:
return 0
res = float('inf')
for s in line_sets:
if (s | used_mask) != used_mask:
res = min(res, 1 + dfs(used_mask | s))
return res
print(dfs(0))
if __name__ == "__main__":
main()
MasKoaTS