eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

Chain

Consider an isothetic rectangle (where "isothetic" means "with sides parallel to coordinate axes"), left bottom corner has coordinates (\textbf{0}, \textbf{0}), right top one --- (\textbf{x_max}, \textbf{y_max}). There are \textbf{N} points \textbf{P_1} (\textbf{x_1}, \textbf{y_1}), \textbf{P_2} (\textbf{x_2}, \textbf{y_2}), …, \textbf{P_N} (\textbf{x_N}, \textbf{y_N}) inside the rectangle (\textbf{0} < \textbf{x_i} < \textbf{x_max}, \textbf{0} < \textbf{y_i} < \textbf{y_max}). Consider polygonal chains \textbf{SP_i1P_i2ΚP_ikF} satisfying the following constraints: \begin{enumerate} \item All internal vertices \textbf{P_ij} are some of the given points; quantity of selected points can be any \textbf{0} ≤ \textbf{k} ≤ \textbf{N}; \item Start vertex \textbf{S} (\textbf{x_S}, \textbf{y_S}) is located on the left side of the rectangle or outside it to the left (\textbf{x_S} ≤ \textbf{0}, \textbf{0} ≤ \textbf{y_S} ≤\textbf{y_max}); \item End vertex \textbf{F}(\textbf{x_F}, \textbf{y_F}) is located on the right side of the rectangle or outside it to the right (\textbf{x_F} ≥ \textbf{x_max}, \textbf{0} ≤ \textbf{y_F}≤ \textbf{y_max}). \end{enumerate} Let’s call such chain \textit{constant-length} if and only if Euclidean lengths of all segments are equal (\textbf{|SP_i1| = |P_i1P_i2| = Κ = |P_ikF|}). It’s easy to see that there is at least one constant-length polygonal chain for any rectangle and any set of given points: this is segment \textbf{SF} with coordinates \textbf{S}(\textbf{0}, \textbf{0}), \textbf{F}(\textbf{x_max}, \textbf{0}) which satisfies all the constraints. Your task is to write a program to find a constant-length chain with \textit{minimal} length of segment. It is easy to see that square (second degree) of the minimal length is always integer, so program should output square of the length, as integer number. \InputFile The first line of input data contains three space-separated integers\textbf{ x_max} \textbf{y_max} \textbf{N} --- coordinates of the right-top corner and number of given points. Each of the following \textbf{N} lines contains two space-separated integers \textbf{x_i} \textbf{y_i} --- coordinates of given point. \textit{\textbf{Constraints}}: \textbf{1} ≤ \textbf{N} ≤ \textbf{1000}; \textbf{5} ≤ \textbf{x_max}, \textbf{y_max} ≤ \textbf{32000}; for all \textbf{1} ≤ \textbf{i} ≤ \textbf{N}, \textbf{0} < \textbf{x_i} < \textbf{x_max}, \textbf{0} < \textbf{y_i} < \textbf{y_max}. \OutputFile Your program should write exactly one integer: square of the minimal possible segment length among constant-length polygonal chains. \includegraphics{https://static.e-olymp.com/content/b0/b0f3a96e7cbd39c529c56bb96195f487172667d8.jpg} \includegraphics{https://static.e-olymp.com/content/b0/b0f3a96e7cbd39c529c56bb96195f487172667d8.jpg} \textit{\textbf{Note}}: We may build some constant-length chains with length (for example: (\textbf{--2}, \textbf{6}), (\textbf{2}, \textbf{8}), (\textbf{6}, \textbf{6}), (\textbf{6+}, \textbf{6})), but cannot build any constant-length chain for smaller lengths.
Лимит времени 0.5 секунд
Лимит использования памяти 256 MiB
Входные данные #1
10 10 6
1 6
3 6
6 6
2 8
9 8
9 1
Выходные данные #1
20
Источник ACM-ICPC Ukraine 2012, 2nd Stage Ukraine, September 6, 2012