302450: CF471E. MUH and Lots and Lots of Segments
Memory Limit:512 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
MUH and Lots and Lots of Segments
题意翻译
来自圣彼得堡动物园的北极熊 Menshykov 和 Uslada 以及来自基辅动物园的大象 Horace 决定画一些画。当他们试图创作他们的第一部杰作时,他们在一张纸上做了一个草稿。该草案包括nn段。每个部分是水平的或垂直的。现在小伙伴们想通过删除一些片段或部分片段来简化草稿,使最终的杰作满足三个条件: 1.Horace希望能够一次画出整幅画:将画笔放在纸上,在画好之前永远不要取下它。刷子可以多次绘制同一个地方。这就是为什么所有剩余的段必须形成一个单一的连接形状。 2.Menshykov 希望得到的形状简单。他将简单形状定义为不包含任何循环的形状。 最初,草图上的所有线段都具有整数起点和终点坐标。Uslada 不喜欢真实坐标,她希望在所有更改后满足这个条件。 3.由于其他部分草稿已经很漂亮,朋友们决定删除草稿中剩余片段长度之和尽可能大的部分。你的任务是计算所有额外段被删除后剩余长度的最大总和。题目描述
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to do some painting. As they were trying to create their first masterpiece, they made a draft on a piece of paper. The draft consists of $ n $ segments. Each segment was either horizontal or vertical. Now the friends want to simplify the draft by deleting some segments or parts of segments so that the final masterpiece meets three conditions: 1. Horace wants to be able to paint the whole picture in one stroke: by putting the brush on the paper and never taking it off until the picture is ready. The brush can paint the same place multiple times. That's why all the remaining segments must form a single connected shape. 2. Menshykov wants the resulting shape to be simple. He defines a simple shape as a shape that doesn't contain any cycles. 3. Initially all the segment on the draft have integer startpoint and endpoint coordinates. Uslada doesn't like real coordinates and she wants this condition to be fulfilled after all the changes. As in other parts the draft is already beautiful, the friends decided to delete such parts of the draft that the sum of lengths of the remaining segments is as large as possible. Your task is to count this maximum sum of the lengths that remain after all the extra segments are removed.输入输出格式
输入格式
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to do some painting. As they were trying to create their first masterpiece, they made a draft on a piece of paper. The draft consists of $ n $ segments. Each segment was either horizontal or vertical. Now the friends want to simplify the draft by deleting some segments or parts of segments so that the final masterpiece meets three conditions: 1. Horace wants to be able to paint the whole picture in one stroke: by putting the brush on the paper and never taking it off until the picture is ready. The brush can paint the same place multiple times. That's why all the remaining segments must form a single connected shape. 2. Menshykov wants the resulting shape to be simple. He defines a simple shape as a shape that doesn't contain any cycles. 3. Initially all the segment on the draft have integer startpoint and endpoint coordinates. Uslada doesn't like real coordinates and she wants this condition to be fulfilled after all the changes. As in other parts the draft is already beautiful, the friends decided to delete such parts of the draft that the sum of lengths of the remaining segments is as large as possible. Your task is to count this maximum sum of the lengths that remain after all the extra segments are removed.
输出格式
Print a single integer — the maximum sum of lengths for the remaining segments.
输入输出样例
输入样例 #1
2
0 0 0 1
1 0 1 1
输出样例 #1
1
输入样例 #2
4
0 0 1 0
0 0 0 1
1 -1 1 2
0 1 1 1
输出样例 #2
5