Created
May 9, 2016 19:34
-
-
Save sholev/2f5a0d3c1a20f68798290104e779b01b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Numerics; | |
// http://bgcoder.com/Contests/Practice/Index/143#1 | |
class OffensiveName | |
{ | |
static void Main(string[] args) | |
{ | |
var array = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); | |
BigInteger mollyFlowers = 0; | |
BigInteger dollyFlowers = 0; | |
long mollyPosition = 0; | |
long dollyPosition = array.Length - 1; | |
string winner; | |
while (true) | |
{ | |
if (array[dollyPosition] == 0 && array[mollyPosition] == 0) | |
{ | |
winner = "Draw"; | |
break; | |
} | |
if (array[mollyPosition] == 0) | |
{ | |
winner = "Dolly"; | |
dollyFlowers += array[dollyPosition]; | |
break; | |
} | |
if (array[dollyPosition] == 0) | |
{ | |
winner = "Molly"; | |
mollyFlowers += array[mollyPosition]; | |
break; | |
} | |
long mollyNextMove = array[mollyPosition]; | |
long dollyNextMove = array[dollyPosition]; | |
if (mollyPosition == dollyPosition) | |
{ | |
mollyFlowers += array[mollyPosition] / 2; | |
dollyFlowers += array[mollyPosition] / 2; | |
if (array[mollyPosition] % 2 == 0) | |
{ | |
array[mollyPosition] = 0; | |
} | |
else | |
{ | |
array[dollyPosition] = 1; | |
} | |
} | |
else | |
{ | |
mollyFlowers += array[mollyPosition]; | |
array[mollyPosition] = 0; | |
dollyFlowers += array[dollyPosition]; | |
array[dollyPosition] = 0; | |
} | |
mollyPosition += mollyNextMove % array.Length; | |
dollyPosition -= dollyNextMove % array.Length; | |
if (mollyPosition >= array.Length) | |
{ | |
mollyPosition -= array.Length; | |
} | |
if (dollyPosition < 0) | |
{ | |
dollyPosition += array.Length; | |
} | |
} | |
Console.WriteLine(winner); | |
Console.WriteLine(mollyFlowers + " " + dollyFlowers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment