fork download
  1. from fractions import Fraction
  2. import sys
  3.  
  4. sys.setrecursionlimit(10000)
  5.  
  6. def parse(inFile):
  7. return (inFile.getInt(), [z - 1 for z in inFile.getInts()])
  8.  
  9. def whatis(N, hs):
  10. xs = []
  11. for i in xrange(N - 1):
  12. rec = i + 1
  13. for j in xrange(i + 2, N):
  14. if (hs[j] - hs[i]) * (rec - i) > (hs[rec] - hs[i]) * (j - i):
  15. rec = j
  16. xs += [rec]
  17. return xs
  18.  
  19. def shift(k):
  20. n = len(k)
  21. return [(n - i) + k[i] for i in xrange(n)]
  22.  
  23. def slv(xs, i, j):
  24. if (i > j): return []
  25. if (i == j): return [0]
  26. return [0] + shift(slv(xs, i + 1, xs[i] - 1)) + slv(xs, xs[i], j)
  27.  
  28. def solve((N, xs)):
  29. for j in xrange(N - 1):
  30. for k in xrange(j + 1, xs[j]):
  31. if xs[k] > xs[j]:
  32. return "Impossible"
  33. hs = slv(xs, 0, N - 1)
  34. mh = max(hs)
  35. hs = [mh - i for i in hs]
  36. return " ".join(["%d" % h for h in hs])
  37.  
  38. if __name__ == "__main__":
  39. from GCJ import GCJ
  40. GCJ(parse, solve, "/Users/lpebody/gcj/2012_2/c", "C").run()
  41.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty