You are given a Young diagram.
Given diagram is a histogram with nn columns of lengths a1,a2,…,ana1,a2,…,an (a1≥a2≥…≥an≥1a1≥a2≥…≥an≥1).
![](https://espresso.codeforces.com/94e21a4955f87bc6a87fae2c191cb199091d11b4.png)
Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1×21×2 or 2×12×1rectangle.
The first line of input contain one integer nn (1≤n≤3000001≤n≤300000): the number of columns in the given histogram.
The next line of input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤300000,ai≥ai+11≤ai≤300000,ai≥ai+1): the lengths of columns.
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
5 3 2 2 2 1
4
Some of the possible solutions for the example:
Meaning of the questions: to give you a chart like the one above of young, before a height greater than equal to the height of a post, asked 2X1 matrix can lay down how many 1X2, or?
This analysis can be seen bipartite matching, because the adjacent two points to match into a matrix, then we build map? There are 5 * 5 th power of two sides * 3 * 3 * 10 10 (not mistaken analysis), Hungary match is O (n * m). I do not think, impossible.
So how can simulate the correct answer? We use black and white staining, direct black and white coloring, color dye out of the fewest matches is a good matrix. For more details, please see the comments:
#include <bits / STDC ++ H.> the using namespace STD; #define LL Long Long int LL A [300005]; LL C [2]; int main (void) { int n-; Scanf ( "% D", & n-); for (int I =. 1; I <= n-; I ++) { Scanf ( "% LLD", & A [I]); // left to right, the first column above each dyeing begin // dyed white c [0] + = a [i] / 2 ; // white // then dyed black c [1] + = a [ i] / 2; // black if (a [i]% 2 == 1) // this column cardinality two, there must be a point of a polychromatic color // number of columns this point consider only what color dye will do c [i% 2] ++; // dyed white on the provisions of the odd columns, even column dyed black // is because if the line did not have a stain, this line also did not have a stain // order to allow more adjacent matching black and white dots, then only make a front and a rear dyed a different color // printf ( "0: % D. 1:% D \ n-", C [0], C [. 1]); } LL COUNT = min (C [0], C [. 1]); the printf ("% LLD \ n-", COUNT); return 0; }
Reference to Part: https: //www.cnblogs.com/YDDDD/p/12082619.html