Codeforces Beta Round #37 C. Old Berland Language
短い順に単語を割り当てていく。例えば長さが、3, 3, 3, 5, 5ならば、
000 001 010 01100 01101
多倍長整数を使うと楽。
N = input() l = map(int,raw_input().split()) ans = [""]*N c = 0 d = 0 while True: p = -1 for i in range(N): if ans[i]=="" and ( p==-1 or l[i]<l[p] ): p = i if p==-1: break c <<= l[p]-d d = l[p] ans[p] = format(c,"0%sb"%l[p]) c += 1 if c>=1<<l[p]: break if ans.count("")==0: print "YES" for a in ans: print a else: print "NO"