{"problem":{"name":"C. Rikka with Consistency","description":{"content":"On the way to the Moscow, Rikka knows someone will replace her. Who is the guy? A devil to get in touch with her dark side, or an angel to rinse the shadow off her mind? However, Rikka knows that her ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":8000,"memory_limit":1048576},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10201C"},"statements":[{"statement_type":"Markdown","content":"On the way to the Moscow, Rikka knows someone will replace her. Who is the guy? A devil to get in touch with her dark side, or an angel to rinse the shadow off her mind? However, Rikka knows that her successor has a special name, whose meaning in Chinese is Consistency. The process of replacement is so wonderful and sentimental, which is what you all must know.\n\nNow, the only road from Beijing to Moscow is described as a broken line with $n$ segments in the $X$-$H$ plane. The $i$-th segment connects the points $(i -1, h_{i -1})$ and $(i, h_i)$, and $h_0 = h_n = 0$ are known. This figure is a topographic map showing the whole trip from Beijing to Moscow and its $H$ axis indicates the altitude. The distance of a path between two points is the length of the broken line between their corresponding points in the map.\n\nAt the outset of the trip, Rikka is in Beijing whose location in the $X$-$H$ plane is $(0, 0)$; Consistency, the guy who will replace Rikka, is in Moscow which is located at $(n, 0)$. Consistency always maintains consistent academic standards, a consistent life level, a consistent height of perspective and the altitude as what Rikka owns. This is why their heights are the same yesterday, today and forever.\n\nNow Rikka wants you to calculate the minimum total distance they need (which is the total length of paths that Rikka and Consistency travel along). By the time that Rikka arrives in Moscow and Consistency arrives in Beijing as well, their replacement will be finished (and this is the ending which is also a new beginning).\n\nThe input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 500$), the number of test cases.\n\nFor each test case, the first line contains a single integer $n$ ($1 <= n <= 50$), the number of segments.\n\nThe second line contains $(n + 1)$ integers $h_0, h_1, \\\\\\\\cdots, h_n$ ($0 <= h_i <= 50$), satisfying $h_0 = h_n = 0$.\n\nThe input guarantees that the paths for each test case always exist.\n\nFor each test case, output a single line with a single number, the minimum total distance they need. Your answer is considered correct if its absolute or relative error does not exceed $10^(-9)$. Formally, let your answer be $a$, and Rikka's answer be $b$. Your answer is considered correct if $frac(| a -b |, max (1 , | b |)) <= 10^(-9)$.\n\n## Input\n\nThe input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 500$), the number of test cases.For each test case, the first line contains a single integer $n$ ($1 <= n <= 50$), the number of segments.The second line contains $(n + 1)$ integers $h_0, h_1, \\\\\\\\cdots, h_n$ ($0 <= h_i <= 50$), satisfying $h_0 = h_n = 0$.The input guarantees that the paths for each test case always exist.\n\n## Output\n\nFor each test case, output a single line with a single number, the minimum total distance they need. Your answer is considered correct if its absolute or relative error does not exceed $10^(-9)$. Formally, let your answer be $a$, and Rikka's answer be $b$. Your answer is considered correct if $frac(| a -b |, max (1 , | b |)) <= 10^(-9)$.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case:  \n- Let $ n \\in \\mathbb{Z} $ be the number of segments.  \n- Let $ H = (h_0, h_1, \\dots, h_n) $ be a sequence of altitudes, with $ h_0 = h_n = 0 $.  \n- The terrain is modeled as a piecewise linear path in the $ X $-$ H $ plane, with segments connecting $ (i-1, h_{i-1}) $ to $ (i, h_i) $ for $ i = 1, \\dots, n $.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 500 $  \n2. $ 1 \\le n \\le 50 $  \n3. $ 0 \\le h_i \\le 50 $ for all $ i \\in \\{0, 1, \\dots, n\\} $, and $ h_0 = h_n = 0 $  \n\n**Objective**  \nRikka starts at $ (0, 0) $ and moves to $ (n, 0) $.  \nConsistency starts at $ (n, 0) $ and moves to $ (0, 0) $.  \nAt every integer time step $ t \\in \\{0, 1, \\dots, n\\} $, their altitudes must be equal: $ h_R(t) = h_C(t) $.  \nThe total distance traveled is the sum of the Euclidean lengths of their respective paths.  \n\nMinimize the total path length:  \n$$\n\\min \\sum_{i=1}^n \\sqrt{1 + (h_{R,i} - h_{R,i-1})^2} + \\sum_{i=1}^n \\sqrt{1 + (h_{C,i} - h_{C,i-1})^2}\n$$  \nsubject to:  \n- $ h_{R,0} = 0, h_{R,n} = 0 $  \n- $ h_{C,0} = 0, h_{C,n} = 0 $  \n- $ h_{R,i} = h_{C,i} = h_i $ for all $ i \\in \\{0, 1, \\dots, n\\} $  \n\n**Note**: Since both must follow the same altitude profile $ h_i $ at each integer $ x $-position, the minimal total distance is simply twice the length of the path from $ (0,0) $ to $ (n,0) $ along the given terrain:  \n$$\n2 \\sum_{i=1}^n \\sqrt{1 + (h_i - h_{i-1})^2}\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10201C","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}