結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー timi
提出日時 2025-10-05 10:43:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 4,814 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 112,120 KB
最終ジャッジ日時 2025-10-05 10:44:09
合計ジャッジ時間 6,397 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int, input().split())
S=input()
dp=[1]
for i in range(N-1,-1,-1):
  if i==N-1:
    if S[i]=='0':
      dp.append(0)
    else:
      dp.append(1)
  else:
    dp.append(0)
    if S[i]!='0':
      dp[-1]+=dp[-2]
    else:
      continue
    s,t=int(S[i]),int(S[i+1])
    if s*10+t<=26:
      dp[-1]+=dp[-3]
  if dp[-1]>K:
    dp[-1]=K
  

dp=dp[::-1]
dp.append(0)
T='!abcdefghijklmnopqrstuvwxyz'
ans=[]
now=0
while now<N:
  x=dp[now+1]
  if x==0:
    ans.append(T[int(S[now])])
    now+=1
  elif x<K:
    a,b=S[now],S[now+1]
    ans.append(T[int(a+b)])
    now+=2
    K-=x
  else:
    a=S[now]
    if int(a)==0:
      if ans[-1]=='b':
        ans[-1]='t'
      if ans[-1]=='a':
        ans[-1]='j'
    else:
      ans.append(T[int(a)])
    now+=1
print(''.join(ans))
0