Solution
Not hard, But need consider carefully. Still can be kind of game problem.
Let define the concepts below:
Top of mountain
,Bottom of mountain
。Top of mountain means the point $i$ which $p_i > p_{i\pm{1}}$. Bottom of mountain means the $i$ which $p_i<p_{i\pm{1}}$.Left/Right side of mountain
. Left/Right the side between two nearbytop of mountain
andbottom of mountain
.Length of side
. Of course the length of the side of mountain. The length of side can apply for left side and right side.
conclusion:
Let's say the maximal value of Length of side
is max
.
If and only if there is only one top of mountain
$i$, both the lenght of left side of $i$
and the lenght of right side of $i$
are max
and the max
is odd. Then this $i$ is the only solution.
Otherwise, just print 0.
Prove case by case:
- If Qingshan not choose the
top of mountain
whichlength
is notmax
. Then Dainel only need start from thebottom of mountain
whichlength
ismax
. - If there are no less than two side's
length
is max, and the these two side is not for the sametop/bottom of mountain
. Then whatever Qingshan choose (of course one oftop of mountain
), Daniel only need choose another one. So no possible two win. Just print 0. - If the two side which
length
ismax
is two side for abottom of mountain
. Then Daniel only need choosethe bottom of mountain
. Then Qingshan will lose. Just print 0. - If only one
side
whichlength
ismax
. Then Dainel only need choose the point in the side. Which distance between that point andthe top of mountain
is even, and this distance longer thanlength of another side
. Then Qingshang will always lose. Because if Qingshan go to Daniel side, because it's even, it will lose. If Qingshan go to another side, then thelength
is lesser than Daniel. So just print 0. - If both
side
oftop of mountain
ismax
. But themax
is even. Then of cours, Qingshan will chose thetop
and Dainel will chose thebottom
. If Qingshan go with Dainel side, then because of even, Qingshan will lose. If Qingshan go with another side, then because of same length, Qingshan will lose. Just print 0. - If not all the case above. the case is the
length of both side of top
is same, and thislenght
ismax
, and thismax
is odd. Then Qingshan chose thetop
, Daniel chosebottom
can win. Print 1.
Code
Forgot case #5 when I was solving this problem at beginning. Got WA answer before I realized that.