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!!!
No comments:
Post a Comment