# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22354 | - - - - - - - List of honorable mention follows - - - - - - - (#40) | Joyful KMP (KRIII5_JK) | Cpython 2 | 13 ms | 2 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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 |
---|---|---|---|---|
Fetching results... |