TC = input() for tc in range(1, TC+1): r, c, b = map(int, raw_input().split()) f = (r*c)-b; if r==1: st = "c" + "."*(f-1) + "*"*b elif c==1: st = ("c\n" + ".\n"*(f-1) + "*\n"*b)[:-1] elif f==1: st = "c" + (("*"*c + "\n")*r)[1:-1] elif f%2==0 and f<4: st = "Impossible" elif f%2==1 and f<9: st = "Impossible" elif f%2==1 and (r<3 or c<3): st = "Impossible" elif f%2==0 and f < 2*c: st = "c" + (("."*(f/2) + "*"*(c - f/2) + "\n")*2 + ("*"*c + "\n")*(r-2))[1:-1] elif f%2==1 and f < (2*c + 3): x = (f-3)/2 st = "c" + (("."*x + "*"*(c-x) + "\n")*2 + ("."*3 + "*"*(c-3) + "\n") + ("*"*c + "\n")*(r-3))[1:-1] elif f%c==1: st = "c" + (("."*c + "\n")*(f/c - 1) + ("."*(c-1) + "*\n") + ("."*2 + "*"*(c-2) + "\n") + ("*"*c + "\n")*(r - f/c - 1))[1:-1] else: st = "c" + (("."*c + "\n")*(f/c) + ("."*(f%c) + "*"*(c - f%c) + "\n")*(f%c>0) + ("*"*c + "\n")*(r - f/c - (f%c>0)))[1:-1] print "Case #%d:\n%s"%(tc, st)

This week is the start of the codejam. Some of the problems this year were okay, I did the first 2 pretty quickly, but this 3rd one is rather tricky. There are many cases that I have to account for. I tried a few submissions, each time finding more special cases then the last. Finally I gave up.

Today, I went online to search for a working solution. This is my implementation of it in python. The document is pretty comprehensive. Although my solution is similar, there is one case which I did not accounted for, which is the last case of the non-single mine special case.

Anyway, this was a pretty fun experience. As of now, I have completed the first 3 questions, and if I have the time next week I will be embarking on the 4th question, the hardest in the set.