CJam、68 61 84 ... 59 49 48 79バイト
l~]__,+:+M@{:Ze<:X2/)_2*X-@+@@-\Z}*;[YY]/_,(\R*_,,:)W%{2\2*1a*+2+/_S*\,(@+\}/;+
問題と同じ形式で入力を受け取ります。
更新:@nutkiによって指摘されたものと同様のテストケースのアルゴリズムを修正しました。コードのサイズがほぼ2倍になりましたが、修正されたので、今からゴルフを試してみましょう。
それがどのように機能するか (少し不完全です、2 1 2後でパリティの説明を追加します)
この質問を見るとすぐに、答えを得るための数式があることがわかりました。いくつかの組み合わせを試した後、私は式が2 * Number of blocks - Number of shared streets
2 1ケースをチェックしましょう:
2 * 3 - 2 = 4
正しい。
3 1 2 4ケースを確認しましょう:
2 * 10 - 10
もう一度訂正してください。イピー、コードは
l~]:L:+2*L:(:+L(+-[{_@e<}*]:+-
これをいくつかの例で試してみましょう:
3 3
出力:
2 * 6 - 7 = 5
しかし、待ってください、実際の答えは6です。
別のものを試してみましょう:
5 5
2 * 10 - 13 = 7 // Answer is 9 instead.
パターンが見えますか?
N NNがより大きい正の整数であるすべてのブロックペアについて、上記の式とは別に追加のcopが2必要ですfloat((N+1)/2)-1。もう一度確認してみましょう:
5 5 3
2 * 13 - 18 = 8 // Answer is 11
上記の例では、1 5 5つのペアと1 3 3つのペア(5 3ブロックから)があります。
別の例を試してみましょう
5 5 4 4
2 * 18 - 27 = 9 // Answer is actually 14
あなただけがあることを考えなければなりません5 5、3 3と3 3のペア(ブロックから5 5、5 4および4 4RESP。)、これのみ4余分な警官が必要ですが、もう一つのペアがあります。
ブロックからは4 4、使い切っただけな3 3ので1 1空きがあります。これは3 3、下の画像を使用して視覚化できる別のブロックペアを構成します。

輪郭を描かれた赤は通常のペアであり、輪郭を描かれた青は垂直方向のペアです。
概説されている赤はペアの片側だけを共有しているのに対し、青いものは片側+ 1ブロックを共有しているため、説明するのは難しいです。しかし、このロジックはすべてのブロックの組み合わせで機能します。
コードは今それを単に計算しています。
l~]__ "Read the input numbers, convert to array and make two copies";
,+ "Get the number of columns and add that to the block array";
:+ "Sum the array elements to get number of blocks + columns";
M@ "Push empty array to stack and rotate input array to top";
{ }* "Run this block for each pair in the block array";
:Ze<:X "Store the later block size in Z, and minimum of two in X";
@\- "Rotate swap and subtract shared sides from total sum";
X)Y/(:T+ "Increment halve and decrement. Store in T and add to sum";
XTY*- "Find unused blocks from this pair for perpendicular pairs";
@+ "Add unused blocks to the array M";
Z "Push Z to stack to be used in next iteration";
;[YY] "Pop the last pushed Z and push array [2 2] to stack";
/,(+ "Check how many perpendicular pairs exist, add to total sum";
次の2 * Number of blocks - Number of shared sidesように書くこともできます
Number of blocks + Number of columns - Number of shared sides between adjacant columns
ここでオンラインでお試しください