classSolution{public:longlongflowerGame(intn,intm){// Alice wins if x + y is odd, occurring when:// 1. x is even and y is odd, or// 2. y is even and x is odd.constintxEven=n/2;constintyEven=m/2;constintxOdd=(n+1)/2;constintyOdd=(m+1)/2;returnstatic_cast<long>(xEven)*yOdd+static_cast<long>(yEven)*xOdd;}};
1 2 3 4 5 6 7 8 9101112
classSolution{publiclongflowerGame(intn,intm){// Alice wins if x + y is odd, occurring when:// 1. x is even and y is odd, or// 2. y is even and x is odd.finalintxEven=n/2;finalintyEven=m/2;finalintxOdd=(n+1)/2;finalintyOdd=(m+1)/2;return(long)xEven*yOdd+(long)yEven*xOdd;}}
1 2 3 4 5 6 7 8 910
classSolution:defflowerGame(self,n:int,m:int)->int:# Alice wins if x + y is odd, occurring when:# 1. x is even and y is odd, or# 2. y is even and x is odd.xEven=n//2yEven=m//2xOdd=(n+1)//2yOdd=(m+1)//2returnxEven*yOdd+yEven*xOdd