fork download
  1. def parse(inFile):
  2. [R,C,D] = inFile.getInts()
  3. return [inFile.readline() for r in xrange(R)]
  4.  
  5. def solve(data):
  6. R = len(data)
  7. C = len(data[0])
  8. sums=[[(0,0,0) for i in xrange(C+1)] for j in xrange(R+1)]
  9. for i in xrange(R):
  10. for j in xrange(C):
  11. w = int(data[i][j])
  12. sums[i+1][j+1] = (2 * w * i, 2 * w * j, w)
  13. for j in xrange(C):
  14. sums[i+1][j+1] = tuple(sums[i+1][j][k] + sums[i+1][j+1][k] for k in xrange(3))
  15. for j in xrange(C,0,-1):
  16. sums[i+1][j] = tuple(sums[i][j][k] + sums[i+1][j][k] for k in xrange(3))
  17. for dim in xrange(min(R,C),2,-1):
  18. for i in xrange(R+1-dim):
  19. for j in xrange(C+1-dim):
  20. ins = [(i,j),(i+dim,j+dim)]
  21. outs = [(i+dim,j),(i,j+dim)]
  22. blade = tuple(sum([sums[i[0]][i[1]][k] for i in ins])-sum([sums[o[0]][o[1]][k] for o in outs]) for k in xrange(3))
  23. for pti in [i, i + dim - 1]:
  24. for ptj in [j, j + dim - 1]:
  25. w = int(data[pti][ptj])
  26. blade = (blade[0] - 2 * w * pti, blade[1] - 2 * w * ptj, blade[2] - w)
  27. if (blade == (blade[2]*(2*i+dim-1),blade[2]*(2*j+dim-1),blade[2])):
  28. return dim
  29. return "IMPOSSIBLE"
  30.  
  31. if __name__ == "__main__":
  32. from GCJ import GCJ
  33. GCJ(parse, solve, "/Users/lpebody/gcj/2011_round2/", "b").run()
  34.  
  35.  
  36.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty