Approach
Depth-first search
For CCC 2011 S3 - Alice Through the Looking Glass, the implementation follows one branch at a time, making it suitable for components, trees, backtracking, or dependency exploration.
- Define the state carried into one recursive or stack frame.
- Mark or choose the current state before exploring children.
- Combine child results or undo the choice when the branch finishes.
Code notes
- 62 lines of Python from the credited upstream file ccc11s3.py.
- The implementation keeps its working state in language-native values and containers.
- No explicit loop blocks detected.
Complexity
Count unique states for graph traversal; for backtracking, count the branching factor and maximum depth.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1234 5678910111213141516171819202122232425262728293031 32 33def crystalSquaresatX(m,x):34 if m >= 1:35 power = 5 ** (m-1)36 location = x power37 if location == 0 or location == 4:38 return 039 elif location == 1 or location == 3:40 return 1 * power + crystalSquaresatX(m - 1, x % power)41 elif location == 2:42 return 2 * power + crystalSquaresatX(m - 1, x % power)43 return maxheightatx44 return 045 46 4748file = open("s3.1.in", 'r')49T = eval(file.readline())50for t in range(0,T):51 line = (file.readline())52 space = line.find(" ")53 m = eval(line[0:space])54 line = line[space+1:]55 space = line.find(" ")56 x = eval(line[0:space])57 y = eval(line[space+1:])58 if y < crystalSquaresatX(m,x):59 print "crystal"60 else:61 print "empty"62