Submission #22352

# Submission time Handle Problem Language Result Execution time Memory
22352 2017-04-30T04:09:35 Z - - - - - - - List of honorable mention follows - - - - - - -(#999, xhae, ainu7, littlesheep) Joyful KMP (KRIII5_JK) PyPy
0 / 7
26 ms 5 KB
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 time Memory Grader output
1 Incorrect 26 ms 5 KB Output isn't correct
2 Halted 0 ms 0 KB -