Saturday, January 13, 2007

An dissapointing topcoder contest....

Yesteday topcoder conducted its srm contest at 10:30 pm . Even though it was pretty late for us i did not mind since i usually sleep late into the night. It was damn cold in my room which was pretty unusual in a city like chennai . I donot know whether it was the climate or was it my body that started freezing ? This was my first top coder srm and i wished i did properly . I was not able to get the gist of the first problem . I got a bit confused . the second problem was regarding a problem validating a knight's move .
the full code is here :http://www.topcoder.com/stat?c=problem_solution&rm=263249&rd=10658&pm=7245&cr=20718854
for (int i = 0; i < cells.length; i+=2) {
if(!this.valid(parse(cells[i]),parse(cells[i+1])))
return "Invalid";
}
this loop was the mistake i did. here what i did was that i paired up two consequtive moves instead of sequence
so suppose you have a sequence of moves say
"D5", "F6", "C6", "A5",

so what my code did was validate knights move from D5->F6 and then the next validate C6->A5
however it should have been
D5->F6, F6->C6,C6->A5 .
then the corrected loop looks something like this
for (int i = 0; i < cells.length; i+=1) {
if(!this.valid(parse(cells[i]),parse(cells[i+1])))
return "Invalid";
}
so its i+=1 and not i+=2!!!!!
damn this seemed to be the easiest that top coder could ask and i messed it up!!!!

the next 1000 sum was easy.......but never did it strike me to use dp or memoization .
so i did the normal way and it took too much time to execute ! :(
http://www.topcoder.com/stat?c=problem_statement&pm=7244&rd=10658&rm=263249&cr=20718854
and here is my solution
http://www.topcoder.com/stat?c=problem_solution&rd=10658&rm=263249&cr=20718854&pm=7244

better luck next time!!!