Submission #22344

#TimeUsernameProblemLanguageResultExecution timeMemory
22344- - - - - - - List of honorable mention follows - - - - - - - (#40)Joyful KMP (KRIII5_JK)Pypy 2
0 / 7
32 ms6 KiB
s = list(raw_input()) K = int(raw_input()) alpha = set() alist = [] for ch in s: if ch not in alpha: alpha.add(ch) alist += [ch] dp = [[-1 for i in range(27)] for j in range(27)] def getCount(usable, slot): if dp[usable][slot] != -1: return dp[usable][slot] ret = -1 if slot == 1: ret = usable else: ret = usable * getCount(usable - 1, slot - 1) dp[usable][slot] = ret return ret print(getCount(26, len(alist)) % 1000000007) if getCount(26, len(alist)) < K: print "OVER" else: cands = list('abcdefghijklmnopqrstuvwxyz') ans = [] usable = 26 slot = len(alist) for a in alist: if slot == 1: ans += cands[K - 1] break for i in range(len(cands)): if K <= getCount(usable - 1, slot - 1): ans += cands[i] cands = cands[:i] + cands[i + 1:] break else: K -= getCount(usable - 1, slot - 1) usable -= 1 slot -= 1 mapping = {} for i in range(len(alist)): mapping[alist[i]] = ans[i] ansstr = '' for ch in s: ansstr += mapping[ch] print ansstr
#Verdict Execution timeMemoryGrader output
Fetching results...